how to user regexp to put single quotes [message #635637] |
Fri, 03 April 2015 15:10 |
gentleman777us
Messages: 122 Registered: April 2005
|
Senior Member |
|
|
Hi,
How can I return a string embeded in single quotes.
ex: select 'hello1, hello2' as val from dual;
would return
val
---
hello1, hello2
I want it to return
val
------
'hello1', 'hello2'
Please note the single quotes around each value.
Any help is greately appreciated.
Thanks
|
|
|
|
|
Re: how to user regexp to put single quotes [message #635643 is a reply to message #635637] |
Sat, 04 April 2015 01:17 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
You could use the quoting string literals technique which was introduced in 10g.
SQL> SELECT q'['hello1', 'hello2']' str FROM DUAL;
STR
------------------
'hello1', 'hello2'
SQL>
But, as your question says "to put single quotes"... you could add the quotes in the beginning and end, and replace the comma and space in between the words with single quotes and comma in between.
SQL> WITH DATA AS(
2 SELECT 'hello1, hello2' str FROM DUAL
3 )
4 SELECT q'[']'||replace(str, ', ', q'[',']')||q'[']' str FROM DATA;
STR
-----------------
'hello1','hello2'
SQL>
Regards,
Lalit
|
|
|