Home » SQL & PL/SQL » SQL & PL/SQL » Escaping single inverted comma (') in oracle ststement (Oracle 10g,Windows XP)
Escaping single inverted comma (') in oracle ststement [message #348945] Thu, 18 September 2008 06:12 Go to next message
joebunny
Messages: 18
Registered: September 2008
Junior Member
HI All,
I am having a problem with my insert query where I am trying to enter user comments in my database.
The problem I face is that when a user tries to enter something having a single inverted comma e.g user's comment, the insert query that I write is not able to parse the single inverted comma in the query string and throws up a error of unclosed literal .
Can anybody suggesxt me how can I escape the single inverted comma and cause my dtata to properly enter in the database.
Any help would be appreciated.
Thanks in advance.
Re: Escaping single inverted comma (') in oracle ststement [message #348947 is a reply to message #348945] Thu, 18 September 2008 06:23 Go to previous messageGo to next message
misragopal
Messages: 125
Registered: June 2005
Location: New Delhi, india
Senior Member

use 2 single quotes instead of using single quote.

like
INSERT into ....
VALUES('USER''S COMMENT');

Re: Escaping single inverted comma (') in oracle ststement [message #348952 is a reply to message #348947] Thu, 18 September 2008 06:43 Go to previous messageGo to next message
joebunny
Messages: 18
Registered: September 2008
Junior Member
yeah sure,
Thanks a lot....!!!!!!!!!!!! Razz
Re: Escaping single inverted comma (') in oracle ststement [message #348980 is a reply to message #348945] Thu, 18 September 2008 08:12 Go to previous messageGo to next message
annagel
Messages: 220
Registered: April 2006
Senior Member
Use bind variables
Re: Escaping single inverted comma (') in oracle ststement [message #349137 is a reply to message #348945] Fri, 19 September 2008 01:34 Go to previous message
_jum
Messages: 508
Registered: February 2008
Senior Member
In some cases you want to use alternative literal strings
beginning with q' or Q' and the new delimiter (here '#').
So You could:
select q'#USER'S COMMENT#' from dual;

Previous Topic: regarding a query
Next Topic: Selecting Partial Duplicate Records
Goto Forum:
  


Current Time: Fri Dec 02 12:02:24 CST 2016

Total time taken to generate the page: 0.10826 seconds