如何在 db2 sql 中转义撇号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2442205/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 05:40:31  来源:igfitidea点击:

How does one escape an apostrophe in db2 sql

sqldb2escaping

提问by grenade

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

我正在寻找 T-SQL 的 db2 等价物:

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

回答by brabster

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

''根据DB2 Survival Guide,在 DB2 上也可以使用两个撇号来获得一个撇号。这不适合你吗?

回答by Rakesh Juyal

Brabsteris 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

Brabster是正确的。你应该逃避'''
那么插入奥哈拉,你将不得不写O''Hara
摘自: 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') `

转义字符。

要插入单引号,请使用 2 个单引号 ( '' )。要插入宠物,请使用以下宠物。
示例:插入 MYTABLE (question,answer) 值('你的宠物的名字是什么?','blacky')`

回答by Ahmad Zaidi

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.

将您的查询保留在单引号 (') 中。并且无论您在哪里使用 qoutes,都将其加倍。例如你想插入......我很好。有一个答案。

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

在 SQL 中,我们需要给出.......'我很好。有一个答案。

回答by Keenan Stewart

I was trying to insert into DB2 a regex expression for an email address. I thought I had to escape all characters as outlined at the proceeding link, but escaping only the single quote contained within the regex seems to be all I needed to escape to get it properly inserted into the database:

我试图在 DB2 中插入一个电子邮件地址的正则表达式。我以为我必须按照正在进行的链接中概述的那样转义所有字符,但是只转义正则表达式中包含的单引号似乎是我需要转义以将其正确插入到数据库中的全部内容:

https://www.ibm.com/support/knowledgecenter/en/SSEPGG_10.1.0/com.ibm.db2.luw.admin.ts.doc/doc/c0059609.html

https://www.ibm.com/support/knowledgecenter/en/SSEPGG_10.1.0/com.ibm.db2.luw.admin.ts.doc/doc/c0059609.html