82

How do I insert a record in a column having varchar data type having single quote in it?

Example: first name is ROBERT and last name is D'COSTA

2 Answers 2

155

Use two single-quotes

SQL> SELECT 'D''COSTA' name FROM DUAL;

NAME
-------
D'COSTA

Alternatively, use the new (10g+) quoting method:

SQL> SELECT q'$D'COSTA$' NAME FROM DUAL;

NAME
-------
D'COSTA
Sign up to request clarification or add additional context in comments.

4 Comments

What if we need two successive single quotes? Is this case the "alternative" method is meant for?
@RichouHunter You would use four single quotes : 'D''''COSTA' => D''COSTA. Alternatively: q'$D''COSTA$'
Thanks, this helped me! For reference, here's another Oracle document regarding the alternate quoting syntax for text literals that reads a little better than the linked PL/SQL doc.
@Dank I agree, the SQL reference is clearer than the PL/SQL doc on this subject (I've updated the link to the most recent version).
2

I found the above answer giving an error with Oracle SQL, you also must use square brackets, below;

SQL> SELECT Q'[Paddy O'Reilly]' FROM DUAL;


Result: Paddy O'Reilly

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.