Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting a string with double quotes into a table

Tags:

sql

oracle

I'm using Oracle 10g and I'm having a problem inserting a string with double quotes into a table. This is my statement

INSERT INTO USERS (ID, NAME, USERNAME) VALUES (NULL, "tes", "hello");

The query above fails with the error "Oracle column not allowed here".

If I change double quotes to single quotes, as below the statement is successful.

INSERT INTO USERS (ID, NAME, USERNAME) VALUES (NULL, 'tes', 'hello');

But, I want to insert the double quotes into the table.

Is it possible to have double quote in strings in an insert statement? I don't want to use REPLACE() because my query is automatically generated from an array.

like image 717
Loren Ramly Avatar asked Feb 02 '13 09:02

Loren Ramly


People also ask

How do you pass a string with double quotes?

The basic double-quoted string is a series of characters surrounded by double quotes. If you need to use the double quote inside the string, you can use the backslash character.

Can we use double quotes for string 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.

How do I use double quotes in SQL?

To specify nested quotation marks within an SQL statement in programs, use the C escape character for every double quotation mark inside a string that is delimited by single quotation marks.

How can you include a double quote character into a literal string?

To include a double quote character in a string, type it twice ("") inside the larger string. Thus "Hello" is a string, as is "She said, ""How are you? """.


1 Answers

It is possible. In Oracle, you quote string literals using single quotes.

If you want to insert test into the database then you must quote that as 'test'.

INSERT INTO USERS (NAME) VALUES ('test');

If you want to insert "test" into the database then you must quote that as '"test"'.

INSERT INTO USERS (NAME) VALUES ('"test"');
like image 131
Alen Oblak Avatar answered Oct 17 '22 23:10

Alen Oblak