博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
字符串文字中包含引号
阅读量:7244 次
发布时间:2019-06-29

本文共 3445 字,大约阅读时间需要 11 分钟。

常常有人写SQL时不知道在字符串内的单引号怎么写,其实只要把一个单引号换成两个单引号表示就可以。

示例如下:

SELECT '''' AS c FROM DUALUNION ALLSELECT 'GOO''D' AS c FROM DUAL;

另外,Oracle10g开始引入了q-quote特性,使用q-quote的写法就比较明确了:

SELECT q'[']' AS c FROM DUALUNION ALLSELECT q'[GOO'D]' AS c FROM DUAL;

 

Oracle10g的SQL参考手册中相关描述如下:

Use the text literal notation to specify values whenever 'string' or appears in the syntax of expressions, conditions, SQL functions, and SQL statements in other parts of this reference. This reference uses the terms text literal, character literal, and string interchangeably. Text, character, and string literals are always surrounded by single quotation marks. If the syntax uses the term char, you can specify either a text literal or another expression that resolves to character data — for example, the last_name column of the hr.employees table. When char appears in the syntax, the single quotation marks are not used.

where N or n specifies the literal using the national character set (NCHAR or NVARCHAR2 data). By default, text entered using this notation is translated into the national character set by way of the database character set when used by the server. To avoid potential loss of data during the text literal conversion to the database character set, set the environment variable ORA_NCHAR_LITERAL_REPLACE to TRUE. Doing so transparently replaces the n’ internally and preserves the text literal for SQL processing.

In the top branch of the syntax:

  • c is any member of the user's character set. A single quotation mark (') within the literal must be preceded by an escape character. To represent one single quotation mark within a literal, enter two single quotation marks.
  • ' ' are two single quotation marks that begin and end text literals.

In the bottom branch of the syntax:

  • Q or q indicates that the alternative quoting mechanism will be used. This mechanism allows a wide range of delimiters for the text string.
  • The outermost ' ' are two single quotation marks that precede and follow, respectively, the opening and closing quote_delimiter.
  • c is any member of the user's character set. You can include quotation marks (") in the text literal made up of c characters. You can also include the quote_delimiter, as long as it is not immediately followed by a single quotation mark.
  • quote_delimiter is any single- or multibyte character except space, tab, and return. The quote_delimiter can be a single quotation mark. However, if the quote_delimiter appears in the text literal itself, ensure that it is not immediately followed by a single quotation mark.
  • If the opening quote_delimiter is one of [, {
    , <, or (, then the closing quote_delimiter must be the corresponding ], }, >, or ). In all other cases, the opening and closing quote_delimiter must be the same character.

Text literals have properties of both the CHAR and VARCHAR2 datatypes:

  • Within expressions and conditions, Oracle treats text literals as though they have the datatype CHAR by comparing them using blank-padded comparison semantics.
  • A text literal can have a maximum length of 4000 bytes.

Here are some valid text literals:

'Hello'

'ORACLE.dbs'
'Jackie''s raincoat'
'09-MAR-98'
N'nchar literal'

Here are some valid text literals using the alternative quoting mechanism:

q'!name LIKE '%DBMS_%%'!'

q'<'So,' she said, 'It's finished.'>'
q'{SELECT * FROM employees WHERE last_name = 'Smith';}'
nq'ï Ÿ1234 ï'
q'"name like '['"'

转载于:https://www.cnblogs.com/minisculestep/p/4889939.html

你可能感兴趣的文章
php生成随机数:自定义函数 randstr($length)
查看>>
python学习--random和列表
查看>>
IPV4网段划分
查看>>
解决Oracle 解决Oracle ORA-12505, TNS:listener does not currently know of SID
查看>>
详解Linux下安装配置Nginx
查看>>
Maven使用笔记一
查看>>
STL deque
查看>>
Words For Today [2011-07-08]
查看>>
图像像素的获取和操作(第三天)
查看>>
(转)Array.prototype.slice.call自解
查看>>
测试1
查看>>
使用CSS3的appearance属性改变元素的外观
查看>>
inotify + rsync 实现 linux 文件实时同步
查看>>
RecyclerView的使用,打造一个通用的Adapter
查看>>
MySQL • 源码分析 • mysql认证阶段漫游
查看>>
05-Flutter移动电商实战-dio基础_引入和简单的Get请求
查看>>
疫情延迟 NOIP模拟 二分答案 图论
查看>>
【BZOJ】1023: [SHOI2008]cactus仙人掌图 静态仙人掌(DFS树)
查看>>
Sass使用总结
查看>>
java sql编辑器 动态报表 数据库备份还原 quartz定时任务调度 自定义表单 java图片爬虫...
查看>>