在 Oracle 中使用引号运算符插入一个 semi-colon

Using the quote operator in Oracle to insert a semi-colon

我有以下 SQL 用于更新现有 table、

中的 CSS
SET DEFINE OFF;

UPDATE SCHEMANAME.template
   SET body = q'[
<style type="text/css">
  #header {
    background-color:#004F5D;
    height:100px;
    position:relative;
  }]'
WHERE name = 'CSS';

模板table具有以下结构,

NAME    NOT NULL VARCHAR2(150)
SUBJECT NOT NULL VARCHAR2(4000)
BODY    NOT NULL CLOB
VERSION NUMBER(18)

但是,当我 运行 收到带有 sqlplus 的更新语句时,

ERROR:
ORA-01756: quoted string not properly terminated

SQL> SP2-0734: unknown command beginning "height:100..." - rest of line ignored.
SQL> SP2-0734: unknown command beginning "position:r..." - rest of line ignored.
SQL> SP2-0042: unknown command "}]'" - rest of line ignored.

我正在使用,

SQL*Plus: Release 11.2.0.4.0 Production

对于 Oracle,

Oracle Database 11g Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE    11.2.0.4.0  Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production

在我看来,sqlplus 对 header 块中第一个声明末尾的分号字符感到不安。

我试过发出,

SET ESCAPE OFF

在 运行更新语句之前,问题仍然存在。

我可以通过将 UPDATE 包装在 BEGIN-END 块中来解决这个问题。 这是完成这项工作的唯一方法吗?

quote-operator 是否存在“;”问题在一个街区内?

它似乎将您的更新语句分成 4 个部分 -

  1. UPDATE SCHEMANAME.template SET body = q'[ <style type="text/css"> #header { background-color:#004F5D;

  2. height:100px;

  3. position:relative;
  4. }]'

你能试试下面的查询吗

update SCHEMANAME.template
   SET body = '"'||chr(13)||'<style type="text/css">'||chr(13)||  '#header {'||chr(13)||    'background-color:#004F5D;'||chr(13)||    'height:100px;'||chr(13)||  'position:relative;'||chr(13)||  '}"'
WHERE name = 'CSS';

我正在使用 chr(13) - 换行而不是引用。