Home » SQL & PL/SQL » SQL & PL/SQL » replace a letter ' (Oracle 11g)
replace a letter ' [message #625456] |
Wed, 08 October 2014 06:20 |
|
rohan10k
Messages: 15 Registered: May 2011
|
Junior Member |
|
|
Hi All,
I am using Oracle 11g version.
I want to convert strings as below please help me.
(1)Original string is as below
('Singapore ,New York , Ind'ia')
It has to convert as below
('Singapore,New York, Ind''ia')
(2) Original string is
('One F'ive, Two ,Three ')
It should convert as below
('One F''ive,Two,Three')
Thanks in advance.
|
|
|
Re: replace a letter ' [message #625458 is a reply to message #625456] |
Wed, 08 October 2014 06:30 |
cookiemonster
Messages: 13920 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
replace is your friend, with optional chr:
SQL>
SQL> WITH DATA AS (SELECT 'One F''ive,Two,Three' a FROM dual
2 UNION ALL
3 SELECT 'Singapore ,New York , Ind''ia' a FROM dual
4 )
5 SELECT a, REPLACE(a, '''', '''''') conv_a, REPLACE(a, CHR(39), CHR(39)||CHR(39)) conv2_a
6 FROM DATA;
A CONV_A CONV2_A
---------------------------- --------------------------------- --------------------------------
One F'ive,Two,Three One F''ive,Two,Three One F''ive,Two,Three
Singapore ,New York , Ind'ia Singapore ,New York , Ind''ia Singapore ,New York , Ind''ia
|
|
|
|
|
Re: replace a letter ' [message #625464 is a reply to message #625462] |
Wed, 08 October 2014 06:59 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
SQL> with data as(
2 select q'['Singapore , New York, Ind'ia']' a from dual union all
3 select q'['One F'ive, Two ,Three']' from dual)
4 SELECT A,
5 REPLACE(REPLACE(REPLACE(A, '''', ''''''), ' ,',','),', ',',') conv_a,
6 REPLACE(REPLACE(REPLACE(A, CHR(39), CHR(39)||CHR(39)), ' ,',','),', ',',') conv2_a
7 FROM DATA
8 /
A CONV_A CONV2_A
--------------------------------------------- --------------------------------------------- ---------------------------------------------
'Singapore , New York, Ind'ia' ''Singapore,New York,Ind''ia'' ''Singapore,New York,Ind''ia''
'One F'ive, Two ,Three' ''One F''ive,Two,Three'' ''One F''ive,Two,Three''
SQL>
[Updated on: Wed, 08 October 2014 07:03] Report message to a moderator
|
|
|
|
Re: replace a letter ' [message #625470 is a reply to message #625466] |
Wed, 08 October 2014 08:14 |
joy_division
Messages: 4963 Registered: February 2005 Location: East Coast USA
|
Senior Member |
|
|
And after the answer is given to that, what new restrictions will you bring up?
Why not give all the rules up front to avoid this game?
|
|
|
|
|
Re: replace a letter ' [message #625479 is a reply to message #625476] |
Wed, 08 October 2014 09:17 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
@OP, we have given you more than a start sort of query. Even though you didn't show us what you tried yourself, you been provided complete answer based on your original requirements. Now it is the time for you to SHOW us what you have tried. Be professional. Because, this is NOT a spoon-feeding/homework asssignment forum. Hope you understand and follow the guidelines. Help us and get helped!
|
|
|
Goto Forum:
Current Time: Fri Apr 26 16:30:11 CDT 2024
|