0

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

2 Answers 2

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

This should work.

Sign up to request clarification or add additional context in comments.

1 Comment

Upvoted because it works and it's what was asked for. I agree with Patrick that there's no need for regex here, and I would tend to avoid them (in Oracle) whenever there's a reasonably readable alternative.
1

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.')

4 Comments

No I want it generic. This is just an example
Thought it was too easy. :) Generic in what ways though? What would be constant and what not? Always comma separated values, always the "e." prefix?
always comma separated and always the e. prefix. The words will be changing
While regular expressions are fun and enjoyable, I think there is no need for them here. It is all about the right tool/function for the right circumstance. Maheswaran does provide a good regular expression alternative.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.