如何处理 Oracle SQL 中的单引号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2875257/
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 06:17:46  来源:igfitidea点击:

How to handle a single quote in Oracle SQL

sqloracleescaping

提问by subhashis

How do I insert a record in a column having varchar data type having single quote in it?

如何在具有单引号的 varchar 数据类型的列中插入记录?

Example: first name is ROBERTand last name is D'COSTA

示例:名字是ROBERT,姓氏是D'COSTA

回答by Vincent Malgrat

Use two single-quotes

使用两个单引号

SQL> SELECT 'D''COSTA' name FROM DUAL;

NAME
-------
D'COSTA

Alternatively, use the new (10g+) quoting method:

或者,使用新的 (10g+) 引用方法

SQL> SELECT q'$D'COSTA$' NAME FROM DUAL;

NAME
-------
D'COSTA

回答by Mur3ph

I found the above answer giving an error with Oracle SQL, you also must use square brackets, below;

我发现上面的答案给出了 Oracle SQL 错误,您还必须使用方括号,如下所示;

SQL> SELECT Q'[Paddy O'Reilly]' FROM DUAL;

SQL> SELECT Q'[Paddy O'Reilly]' FROM DUAL;



Result: Paddy O'Reilly

结果:Paddy O'Reilly

回答by Indrajeet Singh

Use single quote in oracle 12 C.

在 oracle 12 C 中使用单引号。

SELECT 'Paddy O''Reilly' FROM DUAL;