zoukankan      html  css  js  c++  java
  • 字符串文字中包含引号

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

    示例如下:

    SELECT '''' AS c FROM DUAL
    UNION ALL
    SELECT 'GOO''D' AS c FROM DUAL;
    

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

    SELECT q'[']' AS c FROM DUAL
    UNION ALL
    SELECT 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 '['"'

  • 相关阅读:
    PHP 关于字符串操作的练习
    PHP 字符串操作
    JavaScript DOM级事件
    JavaScript 会闪烁的文字
    JavaScript 当输入框获得焦点:如果输入框值为空,提示输入你的姓名,当输入框失去焦点,如果输入框值为空,提示用户名不能为空,边框颜色变为红色,如果输入框值不为0,那么不提示边框默认颜色
    Js 特效之鼠标点击出现小心心特效
    JavaScript BOM对象 DOM对象
    JavaScript 当用户在弹出的输入框中输入手机号码后,将手机号码的前7位转化为*号
    JavaScript 编写代码对用户输入内容的输入框进行排查,看有没有敏感字“草”字
    第一次c++作业小结
  • 原文地址:https://www.cnblogs.com/minisculestep/p/4889939.html
Copyright © 2011-2022 走看看