Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

replace in string last occurence of search phrase with new phrase

WestDraytonAug 12 2010 — edited Aug 12 2010
I have table T with sample data below. The data has occurences of phrace "ab" several times, several places. I want to replace LAST occurence of "ab" with value "ab_last". How to write such query?
with T as
(
select 'some symbols
  ab cd
  lot of occurences of ab here
  this is last ab occurence: ab
  some more symbols ' s from dual
)   
select REGEXP_REPLACE(T.s, '([^ab.]+)','\1_last;') as s from T
/*
END some sym_last;bols
  ab cd
  lot of occurences of ab here
  this is last ab occurence: ab
  some more symbols 
*/
I think Oracle doesn't have function "ReplaceLast". And regular expressions cannot specify filter "last of" as i understand. So how to write the query?

Expected result:
'some symbols
  ab cd
  lot of occurences of ab here
  this is last ab occurence: ab_last
  some more symbols '
--
I have version 10g.
This post has been answered by 678284 on Aug 12 2010
Jump to Answer

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Sep 9 2010
Added on Aug 12 2010
13 comments
41,190 views