25

我正在对 Oracle 数据库尝试一个简单的 INSERT 语句。其中一个值是 VARCHAR2 字段,并且插入语句包含一个 & 符号。我该怎么做呢?我尝试了以下方法:

  1. 将 & 转义为 \& 并设置转义
  2. 设置扫描关闭(这会导致 ORA-00922 丢失或无效选项错误)
  3. 设置定义关闭(这会导致 ORA-00922 丢失或无效选项错误)

还有其他想法吗?

4

7 回答 7

32

At the bottom of a SQL window there is a button to disable/enable substitution variables:

enter image description here

于 2015-11-15T11:17:40.980 回答
26

How I solved it is escaping the & with another &.

For example:

INSERT INTO Foo (Bar) VALUES ('Up && Away');

Works nicely. Thanks for all the help

于 2011-08-18T08:59:45.360 回答
13

需要时间熟悉的 PL/SQL Developer 的特性之一是过多的不同窗口类型。

One of these is the COMMAND window, which is basically a SQL*Plus emulator. We can run SQL*Plus commands as well as SQL, so SET ESCAPE, SET DEFINE and indeed SET SCAN OFF work in that window.

于 2011-08-18T08:46:26.697 回答
11

你有没有尝试过这样的事情?

INSERT INTO tablex VALUES ('Sid ' || '&' || ' Nancy');

改进我的第一个答案,您的问题与 PL/SQL Developer 有关。如果您在 PL/SQL Developer 命令窗口中执行您的块,您还可以使用标准的 SET DEFINE OFF,它的工作方式与 SQL*Plus 中的相同。

于 2011-08-18T08:43:12.090 回答
4

the concat worked perfectly fine for me below is what i did in my select statement:

select FUND_NM
FROM PERFORMANCE
WHERE upper(FUND_DESC) in ('My L&' ||'L FUNDS')
于 2012-10-03T13:35:24.277 回答
4

I use chr(38) where I need an ampersand in PL/SQL.

addr:= 'mysite.com/order.aspx?no=5678' || CHR(38) || 'id=947';
--above line gives you 'mysite.com/order.aspx?no=5678&id=947';
于 2015-01-27T17:48:26.850 回答
2

This is just a SQL Editor issue. To resolve this just compile the procedure with SET DEFINE OFF; . Execution which is PL (executing in server) will not face this issue.

于 2017-07-24T11:38:08.083 回答