How can I refer to a variable in the regular expression

Hello friends,

I have this Regexp, extract the County code: (971)
Select regexp_replace (regexp_replace ('05-000971 7910-324324', '\D'),'^ 0 * (971)? 0?') of double;
It is very good and the need...

But, thinking about the future, someone may need to remove the country code (961), so it is better if I put the code in a variable, but

How can I list the County code via a variable since the Regexp:
declare 
a varchar2 (15);
code number := 971;
begin
select regexp_replace(regexp_replace('000971 05 7910 - 324324','\D'),'^0*(code)?0?') into a from dual;
dbms_output.put_line ( a);
end;
but it does not work?

Best regards
Fateh

You must link the value of the variable code in the regular expression pattern


select regexp_replace(regexp_replace('000971 05 7910 - 324324','\D'),'^0*('||code||')?0?') into a from dual 

Tags: Database

Similar Questions

Maybe you are looking for