SQL 在 oracle 中插入包含引号的字符串

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

insert string which includes quotes in oracle

sqlstringoraclesql-insertclob

提问by neverwinter

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

如何在oracle中插入包含引号的字符串?我的代码是

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.

我得到标识符太长错误,因为 xxx'test'yy 是 clob。

how can I do that?

我怎样才能做到这一点?

thx.

谢谢。

回答by Alex Poole

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.

SQL小提琴

回答by óscar López

Try escaping the quotes:

尝试转义引号:

'xxx''test''yy'

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

在 SQL 中,引号可以通过在它们之前添加另一个引号来转义。

回答by Rashmi singh

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

使用单引号两次,而不是一个双引号。例如:

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