943,851 Members | Top Members by Rank

Ad:
  • Oracle Discussion Thread
  • Unsolved
  • Views: 14397
  • Oracle RSS
Dec 9th, 2008
0

How to handle Single Quotes in Pl/SQL?

Expand Post »
hai,

My requirement is given below.
In my application one LOV is there to show Insured names.In that if we query for the name like ahemd's% then it is showing wrong(junk) data..................So,my question is how to add single quote to already existing single quote.........................I tried in many ways but I didn't get any solutions for this...............even I used Q'[]' frunction but no use.................................One more thing,we need to query for that name dynamically means.............

select '&name' from dual;
where '&name' -- you can pass as ahemd's..................but once you give this you will get a eror message like
"ORA-01756: quoted string not properly terminated".please send me solution..........................
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
like_to_learn is offline Offline
9 posts
since Dec 2008
Dec 9th, 2008
0

Re: How to handle Single Quotes in Pl/SQL?

you need to use REPLACE function to work around single quote.
Featured Poster
Reputation Points: 665
Solved Threads: 427
Posting Genius
debasisdas is offline Offline
6,406 posts
since Feb 2007
Dec 10th, 2008
0

Re: How to handle Single Quotes in Pl/SQL?

How can I use Replace function?
I am passing the sting dynamically..............
ex:
SELECT REPLACE('&NAME',''',''''') FROM DUAL; if you run this statement,it will ask the name
then you just enter adem's.....
If you execute that statement you will get
"ORA-01756: quoted string not properly terminated" error..........
please suggest me, is there any way to handle.................
Last edited by peter_budo; Dec 12th, 2008 at 7:09 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
like_to_learn is offline Offline
9 posts
since Dec 2008
Sep 16th, 2009
0

Re: How to handle Single Quotes in Pl/SQL?

I don't think you are still looking for this answer.But I thought I would post answer so that it would be helpful who are following this thread.

assuming that you are trying to eliminate single quote.

sql Syntax (Toggle Plain Text)
  1. SELECT REPLACE('&NAME','''','') FROM DUAL

pass 2 singlequotes in the parameter for adem's

ex:adem''s

would return adems

OR
from the given table

sql Syntax (Toggle Plain Text)
  1. SELECT REPLACE(col1,'''','') FROM TEMP
  2. WHERE col1='adem''s'

The actual data in the column reads as adem's
Last edited by peter_budo; Sep 22nd, 2009 at 9:24 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
irukulapati is offline Offline
1 posts
since Sep 2009
Jan 19th, 2011
0
Re: How to handle Single Quotes in Pl/SQL?
I am trying to solve a similar issue. We need to find all the names that have an apostrophe in it. I tried the code below, but I get the error below the code. Help?

use enterprise
SELECT REPLACE('&fldName_Last','''','') FROM locStaff
where fldName_Last like "'%"


Msg 207, Level 16, State 1, Line 4
Invalid column name ''%'.


I don't think you are still looking for this answer.But I thought I would post answer so that it would be helpful who are following this thread.

assuming that you are trying to eliminate single quote.

sql Syntax (Toggle Plain Text)
  1. SELECT REPLACE('&NAME','''','') FROM DUAL

pass 2 singlequotes in the parameter for adem's

ex:adem''s

would return adems

OR
from the given table

sql Syntax (Toggle Plain Text)
  1. SELECT REPLACE(col1,'''','') FROM TEMP
  2. WHERE col1='adem''s'

The actual data in the column reads as adem's
Reputation Points: 10
Solved Threads: 0
Newbie Poster
amdarden is offline Offline
1 posts
since Jan 2011
Mar 22nd, 2011
0
Re: How to handle Single Quotes in Pl/SQL?
select replace(q'[&test]','''','') from dual
Last edited by ubecdaniweb; Mar 22nd, 2011 at 12:45 pm. Reason: wrong
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ubecdaniweb is offline Offline
1 posts
since Mar 2011
Mar 27th, 2011
0
Re: How to handle Single Quotes in Pl/SQL?
same way,
you can use q'[] function here to solve your problem.
as given by ubecdaniweb


select replace(q'[&test]','''','') from dual;-- for remove wuote from test variable


but, as you questioned, you want to add one more single quote here so you can use following query..

select replace(q'[&test]','''','''''') from dual;
Reputation Points: 6
Solved Threads: 4
Light Poster
pratik_garg is offline Offline
38 posts
since Feb 2011

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Oracle Forum Timeline: Create trigger
Next Thread in Oracle Forum Timeline: How to format output in SQL?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC