Nianios
Nianios

Reputation: 1426

Replace parts in a string using REGEXP_REPLACE

Hi I have a string in oracle like this:

 temp_a, temp_b, temp_c

What I want to get is :

 e.temp_a, e.temp_b, e.temp_c

So I want to put an "e." before every part in this string
I searched in internet and I found examples to split the string or to replace simpler strings but nothing to guide me through my problem

Upvotes: 0

Views: 618

Answers (2)

Maheswaran Ravisankar
Maheswaran Ravisankar

Reputation: 17920

select regexp_replace('temp_a, temp_b, temp_c',
              '([a-zA-Z0-9_]+)(,?)', 
               'e.\1\2') from dual;

This should work.

Upvotes: 1

Bacs
Bacs

Reputation: 919

I just noticed you're specifically asking for regex, but for what it's worth I would probably do it like this:

rtrim( replace( 'e.'||your_string, ', ', ', e.'), 'e.')

Upvotes: 1

Related Questions