How does one escape an apostrophe in db2 sql

2019-03-22 17:35发布

I'm looking for the db2 equivalent of T-SQL's:

INSERT INTO People (Surname) VALUES ('O''Hara');

标签: sql db2 escaping
3条回答
趁早两清
2楼-- · 2019-03-22 18:05

Use two apostrophes '' to get a single apostrophe on DB2 too, according to the DB2 Survival Guide. Isn't that working for you?

查看更多
Luminary・发光体
3楼-- · 2019-03-22 18:08

just make it simple.

Keep your query in the single quotes ('). and where ever you are using qoutes, make it double. for e.g. u want to insert ...... I'm fine. There's an answer.

in SQL we need to give ....... 'I''m fine. There''s an answer.'

查看更多
甜甜的少女心
4楼-- · 2019-03-22 18:10

Brabster is correct. You are supposed to escape ' with ''
So to insert O'Hara , you will have to write O''Hara
Excerpt from: http://www.michael-thomas.com/tech/db2/db2_survival_guide.htm

Escape character.

To insert a single quote, use 2 single quotes ( '' ). To insert pet's use the following pet''s.
Example: insert into MYTABLE (question,answer) values ('What is your pet''s name?','blacky') `

查看更多
登录 后发表回答