OraQA

Oracle Question and Answer

  • Do you have a solution to a problem? Do you have an unanswered question? Login and share it with the Oracle community. More...

Oracle News


Entries RSS feed

Comments RSS feed

How to escape single quotes in strings

March 20th, 2006 By Eddie Awad

Just add one more single quote next to the one you want to escape. For example:

SQL> select 'eddie''s stuff'
  2  from dual
  3  /

'EDDIE''SSTUF
-------------
eddie's stuff

SQL> select 'the sopranos'''
  2  from dual
  3  /

'THESOPRANOS'
-------------
the sopranos'

SQL> select 'ain' || '''' || ' t that nice?'
  2  from dual
  3  /

'AIN'||''''||'TTH
-----------------
ain' t that nice?

2 Responses to “How to escape single quotes in strings”

  1. TMoore Says:

    You can also put:

    SELECT 'alan'||chr(39)||'s database' FROM Dual

    chr( ) take chance to write any character

  2. austrin Says:

    The alternative quoting mechanism introduced with 10g should be mentioned as well.
    e.g. (i hope this example gets formatted right):

    q'(name LIKE '%DBMS_%%')'
    q''
    

    A link to the documentation:
    http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_sqltypes.htm#sthref378

    BR,
    Martin

Leave a Reply

You must be logged in to post a comment.

RSS feed for comments on this question