Home » SQL & PL/SQL » SQL & PL/SQL » Replace every even number occurance of comma with # in a String (Oracle 11g R2)
Replace every even number occurance of comma with # in a String [message #625914] |
Thu, 16 October 2014 02:49 |
|
Gurus,
Hope everythings good at your side.
I have one requirement
I need to replace every EVEN number of occurrence of comma with '#' in a string
For example
If the string is
Abraham, Sibi M.,Abramenkova, Anna,Abreu, Maria Helena,Acevedo, Liliana,Addy, Ibironke
The out put will be
Abraham, Sibi M.#Abramenkova, Anna#Abreu, Maria Helena#Acevedo, Liliana#Addy, Ibironke
So here as we can see that the first comma is retained , the second occurrences is replaced with # 3rd is retained and 4rth occurrences is replaced with # and so on.
Thanks & Regards
Javed A. Khan
|
|
|
Re: Replace every even number occurance of comma with # in a String [message #625918 is a reply to message #625914] |
Thu, 16 October 2014 03:30 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
Are you sure you need the RULE of every even occurrence? Looking at your sample data it seems, all such occurrences will always have the comma together with other characters before and after.
Like, 'Helena,Acevedo' has 'a,A' together as an expression to be replaced by 'a#A'. Unlike, 'Anna,Abreu, Maria Helena,Acevedo' where the other concurrence of comma has a space immediately after it.
|
|
|
|
|
Re: Replace every even number occurance of comma with # in a String [message #625927 is a reply to message #625914] |
Thu, 16 October 2014 05:19 |
|
Michel Cadot
Messages: 68641 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
SQL> with data as (
2 select 'Abraham, Sibi M.,Abramenkova, Anna,Abreu, Maria Helena,Acevedo, Liliana,Addy, Ibironke' val from dual
3 )
4 select regexp_replace(val,'([^,]*,[^,]*),','\1#') from data
5 /
REGEXP_REPLACE(VAL,'([^,]*,[^,]*),','\1#')
--------------------------------------------------------------------------------------
Abraham, Sibi M.#Abramenkova, Anna#Abreu, Maria Helena#Acevedo, Liliana#Addy, Ibironke
|
|
|
|
Goto Forum:
Current Time: Fri Apr 19 09:42:01 CDT 2024
|