Home » SQL & PL/SQL » SQL & PL/SQL » replace with the first occurence in the string (10.2.0.4)
replace with the first occurence in the string [message #570541] Mon, 12 November 2012 00:16 Go to next message
grpatwari
Messages: 198
Registered: June 2008
Location: Hyderabad
Senior Member
Hi,

I am using regexp_replace function to replace the string between the double quotes with the first occurance but i am able to replace first occurance but I am not getting remaining string.

For example:

select REGEXP_replace('Parent.addChildByName("DS-Id of OAL(BROBA)")||parent.add("DS-Id of OAL(BROBA)")','["]:print:+:punct::print:*["]','XXXX') from DUAL

O/P: Parent.addChildByName(XXXX)

Expected O/P : Parent.addChildByName(XXXX)||parent.add("DS-Id of OAL(BROBA)")

Please help on this.
Re: replace with the first occurence in the string [message #570543 is a reply to message #570541] Mon, 12 November 2012 00:54 Go to previous messageGo to next message
Littlefoot
Messages: 19697
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
As you can see, code you posted is malformed.

Could you post test case (i.e. input and desired output)? I don't understand the question (first occurrence of what? Replace it with what?).
Re: replace with the first occurence in the string [message #570544 is a reply to message #570543] Mon, 12 November 2012 01:09 Go to previous messageGo to next message
grpatwari
Messages: 198
Registered: June 2008
Location: Hyderabad
Senior Member
HI,


I want to replace the expression between the double quotes for example

'Parent.addChildByName("DS-Id of OAL(BROBA)")||parent.add("DS-Id of OAL(BROBA)")' in this string

I want to replace the "DS-Id of OAL(BROBA)" with some XXX( only first occurance of the string)

My expected output : 'Parent.addChildByName(XXXX)||parent.add("DS-Id of OAL(BROBA)")'

I used the following query but it is not working.

select REGEXP_replace('Parent.addChildByName("DS-Id of OAL(BROBA)")||parent.add("DS-Id of OAL(BROBA)")','["]:print:+:punct::print:*["]','XXXX') from DUAL

Re: replace with the first occurence in the string [message #570546 is a reply to message #570544] Mon, 12 November 2012 01:27 Go to previous messageGo to next message
Michel Cadot
Messages: 59427
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
SQL> select REGEXP_replace('Parent.addChildByName("DS-Id of OAL(BROBA)")'||'parent.add("DS-Id of OAL(BROBA)")',
  2                        '"[^"]+"','XXXXX',1,1)
  3  from dual;
REGEXP_REPLACE('PARENT.ADDCHILDBYNAME("DS-IDOFOAL(BROBA)")'||
-------------------------------------------------------------
Parent.addChildByName(XXXXX)parent.add("DS-Id of OAL(BROBA)")

1 row selected.

Regards
Michel
Re: replace with the first occurence in the string [message #570550 is a reply to message #570546] Mon, 12 November 2012 03:20 Go to previous message
grpatwari
Messages: 198
Registered: June 2008
Location: Hyderabad
Senior Member
Hi Michel,


The following query is working fine. Thanks a lot.

Regards,
Siva S.
Previous Topic: please help with my code PL/SQL Block
Next Topic: DATABSE_LINK_ERROR
Goto Forum:
  


Current Time: Sat Oct 25 04:55:24 CDT 2014

Total time taken to generate the page: 0.16619 seconds