Vertica Functions - Using arguments
kamil
✭
Guys,
Got some doubts about using functions. Below an example:
create or replace function fname(name varchar2, country varchar2) return varchar2
as begin
return regexp_replace(name, E'.country:(.?)(?=\n).*', E'\1', 1, 0, 'n');
end;
So, is it possible to use input argument country inside regexp_replace?
0
Comments
Yes, function arguments can be used as input to the REGEXP_REPLACE function.
Example:
Ok,
Your example is showing that i can use it as a string and replacement:
REGEXP_REPLACE( string, target [, replacement [, position [, occurrence ... [, regexp_modifiers ] ] ] ] )
but the thing is if arguments can be passed inside target option:
return regexp_replace(name, E'.country:(.?)(?=\n).*', E'\1', 1, 0, 'n');
so:
So can i pass country argument (e.g. US) and gather result like:
return regexp_replace(name, E'.US:(.?)(?=\n).*', E'\1', 1, 0, 'n');
Hi,
See if you can modify how you are passing the data to the REGEXP_REPLACE function.
Example:
(Using a simpler simpler case)
First, verify that the REGEXP_REPLACE works with the simpler case. Here I replace E'US\n' with a zero length string (i.e. ''):
That works. But can I do it in a function?
Not like that!
But like this:
Make sense?
@kamil - I think this is what you are after.
@Jim: yeah! Thats it. Thank you!