954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to handle Single Quotes in Pl/SQL?

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..........................

like_to_learn
Newbie Poster
9 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

you need to use REPLACE function to work around single quote.

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

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.................

like_to_learn
Newbie Poster
9 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

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.

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

SELECT REPLACE(col1,'''','') FROM TEMP
where col1='adem''s'


The actual data in the column reads as adem's

irukulapati
Newbie Poster
1 post since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

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.

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

SELECT REPLACE(col1,'''','') FROM TEMP
where col1='adem''s'

The actual data in the column reads as adem's

amdarden
Newbie Poster
1 post since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

select replace(q'[&test]','''','') from dual

ubecdaniweb
Newbie Poster
1 post since Mar 2011
Reputation Points: 10
Solved Threads: 0
 

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;

pratik_garg
Light Poster
38 posts since Feb 2011
Reputation Points: 6
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You