JokerBean
JokerBean

Reputation: 423

How to escape two single quotes in DB2?

E.g: Code=''. If I use Code ='''', in the result I'm getting only one quote.

Upvotes: 2

Views: 3252

Answers (2)

MichaelTiefenbacher
MichaelTiefenbacher

Reputation: 4005

More information in your qustion would be helpful. Which OS or where exactly you execute it. Here is a working example from a Db2 command line:

db2 create table str(text varchar(20))
DB20000I  The SQL command completed successfully.

db2 "insert into str values '''''' "
DB20000I  The SQL command completed successfully.

db2 select * from str

TEXT
--------------------
''

1 record(s) selected.

Note the double quotes round the SQL to avoid shell interactions/reactions.

Upvotes: 0

jarlh
jarlh

Reputation: 44766

Keep the current start and end quotes. Then double each quote supposed to be a part of the string value.

Code = ''''''

Or you can perhaps use a Unicode string literal:

Code = U&'\0027\0027'

Upvotes: 1

Related Questions