Thanks for the question, santhosh.
Asked: February 24, 2017 - 10:50 am UTC
Last updated: February 28, 2017 - 1:33 am UTC
Version: 11g
Viewed 1000+ times
You Asked
hi team ,
i have a scenario.I have a statement a,b,c, here by using regular expression regexp_replace i need to replace the commas in the statement with ||','|| and the last comma in the statement which is present should be replaced with null.
statement = a,b,c,
The output which i need is a||','||b||','||c
i tried the above statement it works can i write in a better way to in order to reduce the code
my code : select regexp_replace(regexp_replace('a,b,c,','[,]$',''),',','||'',''||');
optimised code?
and Connor said...
SQL> variable str varchar2(30)
SQL> exec :str := 'a,b,c,';
PL/SQL procedure successfully completed.
SQL>
SQL> select
2 replace(rtrim(:str,','),',',q'{||','||}')
3 from dual;
REPLACE(RTRIM(:STR,','),',',Q'{||','||}')
---------------------------------------------------------
a||','||b||','||c
1 row selected.
Rating
(2 ratings)
Is this answer out of date? If it is, please let us know via a Comment