Home » SQL & PL/SQL » SQL & PL/SQL » replace function wont work with single quotes
replace function wont work with single quotes [message #214106] Mon, 15 January 2007 00:10 Go to next message
vikram1780
Messages: 222
Registered: January 2007
Location: Bangalore
Senior Member
Here is the string "here i am sunil"

I just want to replace sunil in the string with 'sunil'

select replace ('here i am sunil','sunil',''sunil'') from dual;

Can anyone help in framing this querry or else any alternative procedure.
Re: replace function wont work with single quotes [message #214108 is a reply to message #214106] Mon, 15 January 2007 00:27 Go to previous messageGo to next message
vamsi kasina
Messages: 2107
Registered: October 2003
Location: Riyadh, Saudi Arabia
Senior Member
You should read the documentation for displaying quotes.
select replace ('here i am sunil','sunil','''sunil''') from dual;
For better understanding check the following
select 'sunil' from dual;
select '''sunil''' from dual;
By
Vamsi
Re: replace function wont work with single quotes [message #214110 is a reply to message #214108] Mon, 15 January 2007 00:37 Go to previous messageGo to next message
vikram1780
Messages: 222
Registered: January 2007
Location: Bangalore
Senior Member
Hi Vamsi thanks a lot

I have one more querry

Here is the string "here i am sunil"
O/P "here i am sunil' "

That is i need a single quote on onside. Please let me know the querry.

Thanks
Re: replace function wont work with single quotes [message #214117 is a reply to message #214110] Mon, 15 January 2007 01:12 Go to previous messageGo to next message
vamsi kasina
Messages: 2107
Registered: October 2003
Location: Riyadh, Saudi Arabia
Senior Member
Quote:
You should read the documentation for displaying quotes.
By
Vamsi
Re: replace function wont work with single quotes [message #214121 is a reply to message #214117] Mon, 15 January 2007 01:20 Go to previous messageGo to next message
vikram1780
Messages: 222
Registered: January 2007
Location: Bangalore
Senior Member
Hey Vamshi,

Definitely I will read the book. Here I am getting syntax error while doing so.

Just give some refrence material where I can read abt strings.

I tried below querry. But it is errored out

select replace ('select then emp else', 'then','' 'then' '' ) from dual
Re: replace function wont work with single quotes [message #214123 is a reply to message #214121] Mon, 15 January 2007 01:25 Go to previous messageGo to next message
vikram1780
Messages: 222
Registered: January 2007
Location: Bangalore
Senior Member
HI Thanks vamshi


I got desired output. Thanks for ur help and suggestion.

Thanks
kumar
Re: replace function wont work with single quotes [message #214125 is a reply to message #214121] Mon, 15 January 2007 01:34 Go to previous message
vamsi kasina
Messages: 2107
Registered: October 2003
Location: Riyadh, Saudi Arabia
Senior Member
Have you tried google?
Dealing with apostrophes/single quotes in strings
Anyway if you want to display a single quote, you need to code
' ''vamsi''krishna'' ' (to display " 'vamsi'krishna' ")
you shouldn't code like the following
'' 'vamsi''krishna' ''

By
Vamsi
Previous Topic: Local Temporary Tables / Oracle vesrion of DB2 temporary table in a session
Next Topic: dependent column
Goto Forum:
  


Current Time: Mon Dec 05 21:26:45 CST 2016

Total time taken to generate the page: 0.08563 seconds