0

I need a simple replace function which replaces a semicolon delimited list of strings to quoted comma delimited strings.

'123;Asd;_P1;' replaces to '123', 'Asd', '_P1'

Tried this but the last string missed the quotes and also string can have other chars.

SELECT REGEXP_REPLACE('123;234;345;123','([[:alnum:]]+);', '''\1'',') List FROM DUAL;

2 Answers 2

1

I don't think you need regexp_replace here, a simple replace should be sufficient. It appears that you just want to replace a semicolon with the string "', '" and then add a single quote before and after the string.

select q'{'}' ||
       replace( '123;234;345;123', ';', q'{','}' ) ||
       q'{'}'
  from dual
Sign up to request clarification or add additional context in comments.

2 Comments

I am not able to make it work in WHERE clause. WHERE Col1 IN (q'{'}' || replace('MK2.3;P002;0001112', ';',q'{','}') || q'{'}')) Can you please let me know what I am missing?
@AnitaKulkarni - That's because you've asked the wrong question. You can't use string transforms to change a single delimited string into a set of strings in a WHERE clause. You can parse a delimited string to populate a collection and use that collection in your query asktom.oracle.com/pls/apex/…
0

SELECT REGEXP_REPLACE( REGEXP_REPLACE('123;234;345;123','([[:alnum:]]+);', '''\1'','), ',([[:alnum:]]+)', ',''\1''') FROM DUAL;

1 Comment

what if the fields contain chars other than alphanumerics? ('_P1' for example)

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.