13

How can I insert string which includes quotes in oracle? my code is

INSERT INTO TIZ_VADF_TL_MODELS (name)
VALUES ('xxx'test'yy');

if I use

INSERT INTO TIZ_VADF_TL_MODELS (name)
VALUES ("xxx'test'yy");

I get identifier is too long error because xxx'test'yy is clob.

how can I do that?

thx.

neverwinter
  • 810
  • 2
  • 15
  • 42

3 Answers3

18

You can also use the 'alternative quoting mechanism' syntax:

INSERT INTO TIZ_VADF_TL_MODELS (name)
VALUES (q'[xxx'test'yy]');

The pair of characters immediately inside the first set of quotes, [] in this case, delimit the quoted text; single quotes within those do not have to be escaped. Of course, you can't then have ]' within the string itself, but you can pick your own delimiters so that can be avoided if it's going to be an issue; ] on its own would still be OK.

This can be simpler than making sure single quotes are escaped, which can get a bit messy, or at least hard to read and debug.

SQL Fiddle.

Alex Poole
  • 183,384
  • 11
  • 179
  • 318
13

Try escaping the quotes:

'xxx''test''yy'

In SQL quotes can be escaped by adding another quote before them.

Óscar López
  • 232,561
  • 37
  • 312
  • 386
3

Use single quotes two times, instead of one double quotes. for eg:

INSERT INTO TIZ_VADF_TL_MODELS (name)
VALUES ('xxx''test''yy');
Nikolay Mihaylov
  • 3,868
  • 8
  • 27
  • 32
Rashmi singh
  • 151
  • 1
  • 5