忽略 sqlplus 查询中的哈希字符

Ignore hash character in a query on sqlplus

我已经在 sql 开发人员上发起了这个查询,没有错误。

    insert into
    COMUNICAZIONI_TEMPLATE (ID, DESCRIZIONE, TESTO_TEMPLATE)
values
    (3, 'TEMPLATE EMAIL NUOVO DOCUMENTO', 'Gentile <strong>$nome $cognome</strong>, <br>
Document list:
<br>
#foreach($doc in $listaDocumentiAssociatiATaleCf)
<strong>$doc.getNomeDocumento()</strong> relativo/a al contratto  <strong>$doc.getNomeProdotto() </strong>, polizza numero <strong>$doc.getNumeroPolizza() </strong> <br>
#end
<br>');

但是当我用 sqlplus 启动它时,出现以下错误:

SP2-0734: unknown command beginning "foreach($d..." - rest of line ignored.
SP2-0042: unknown command "end" - rest of line ignored.

有没有办法忽略字符串中的特殊字符“#”?

这是你现在拥有的:

SQL> select * from comunicazioni_template;

no rows selected

SQL> insert into
  2      COMUNICAZIONI_TEMPLATE (ID, DESCRIZIONE, TESTO_TEMPLATE)
  3  values
  4      (3, 'TEMPLATE EMAIL NUOVO DOCUMENTO', 'Gentile <strong>$nome $cognome</strong>, <br>
  5  Document list:
  6  <br>
  7  #foreach($doc in $listaDocumentiAssociatiATaleCf)
SP2-0734: unknown command beginning "foreach($d..." - rest of line ignored.
  7  <strong>$doc.getNomeDocumento()</strong> relativo/a al contratto  <strong>$doc.getNomeProdotto() </strong>, polizza numero <strong>$doc.getNumeroPolizza() </strong> <br>
  8  #end
SP2-0042: unknown command "end" - rest of line ignored.
  8  <br>');

1 row created.

SQL> select length(testo_template) from comunicazioni_template;

LENGTH(TESTO_TEMPLATE)
----------------------
                   240

实际 已插入,但有错误。

为什么会这样?因为你遇到了SQLPREFIX问题.

Sets the SQL*Plus prefix character. While you are entering a SQL command or PL/SQL block, you can enter a SQL*Plus command on a separate line, prefixed by the SQL*Plus prefix character. SQL*Plus will execute the command immediately without affecting the SQL command or PL/SQL block that you are entering. The prefix character must be a non-alphanumeric character.

默认情况下,散列 #SQLPREFIX 字符。因此,将其更改为不同的内容(您插入的值中没有的内容,例如 !),然后重复操作:

SQL> rollback;

Rollback complete.

SQL> set sqlprefix "!"
SQL> insert into
  2      COMUNICAZIONI_TEMPLATE (ID, DESCRIZIONE, TESTO_TEMPLATE)
  3  values
  4      (3, 'TEMPLATE EMAIL NUOVO DOCUMENTO', 'Gentile <strong>$nome $cognome</strong>, <br>
  5  Document list:
  6  <br>
  7  #foreach($doc in $listaDocumentiAssociatiATaleCf)
  8  <strong>$doc.getNomeDocumento()</strong> relativo/a al contratto  <strong>$doc.getNomeProdotto() </strong>, polizza numero <strong>$doc.getNumeroPolizza() </strong> <br>
  9  #end
 10  <br>');

1 row created.

SQL> select length(testo_template) from comunicazioni_template;

LENGTH(TESTO_TEMPLATE)
----------------------
                   295

SQL>

对;没有更多的错误,长度现在应该是(295 个字符)。