Managing single quotes in Oracle SQL queries
Inserting values containing single quotes in Oracle SQL Database can pose challenges because single quotes themselves serve as string delimiters. For this reason, it's crucial to know how to handle single quotes correctly.
Handling single quotes
To insert a value containing single quotes into a varchar column, you can use two consecutive single quotes. For example, to insert the last name "D'COSTA" into a column named "last_name":
<code class="language-sql">INSERT INTO table (last_name) VALUES ('D''COSTA');</code>
Alternatively, you can use the new (starting with Oracle 10g) quoting method of enclosing the value in single quotes starting with a dollar sign and ending with another dollar sign. This method allows you to use a single single quote in the value:
<code class="language-sql">INSERT INTO table (last_name) VALUES q'$D'COSTA$';</code>
The above is the detailed content of How Can I Properly Insert Single Quotes into Oracle SQL Strings?. For more information, please follow other related articles on the PHP Chinese website!