在 oracle 中插入包含引号的字符串 [英] insert string which includes quotes in oracle

查看:34
本文介绍了在 oracle 中插入包含引号的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

如果我使用

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

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

I get identifier is too long error because xxx'test'yy is clob.

我该怎么做?

谢谢.

推荐答案

您也可以使用 '替代引用机制'语法:

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 小提琴.

这篇关于在 oracle 中插入包含引号的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆