Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle a single quote in Oracle SQL

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

like image 665
subhashis Avatar asked May 20 '10 15:05

subhashis


People also ask

Can you use single quotes in SQL?

Single quotes are used to indicate the beginning and end of a string in SQL. Double quotes generally aren't used in SQL, but that can vary from database to database. Stick to using single quotes. That's the primary use anyway.

How do I insert data into a single quote in Oracle?

The most simple and most used way is to use a single quotation mark with two single quotation marks in both sides. Simply stating you require an additional single quote character to print a single quote character. That is if you put two single quote characters Oracle will print one.

How does Oracle handle apostrophe in SQL?

Answer: Now it is first important to remember that in Oracle, you enclose strings in single quotes. The first quote denotes the beginning of the string and the second quote denotes the termination of the string.


1 Answers

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 
like image 175
Vincent Malgrat Avatar answered Sep 17 '22 19:09

Vincent Malgrat