oracle PL/SQL Developer 中的转义符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7103715/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 03:28:58  来源:igfitidea点击:

Escape ampersand in PL/SQL Developer

oracleescapingspecial-charactersplsqldeveloper

提问by Ray Booysen

I'm trying a simple INSERT statement against an Oracle database. One of the values is a VARCHAR2 field and the insert statement contains an ampersand. How do I do this? I've tried the following methods:

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

  1. Escape the & as \& with set escape on
  2. set scan off (this causes an ORA-00922 missing or invalid option error)
  3. set define off (this causes an ORA-00922 missing or invalid option error)
  1. 将 & 转义为 \& 并设置转义
  2. 设置扫描关闭(这会导致 ORA-00922 丢失或无效选项错误)
  3. 设置定义关闭(这会导致 ORA-00922 丢失或无效选项错误)

Any other ideas?

还有其他想法吗?

回答by Ray Booysen

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

很好用。感谢所有的帮助

回答by William Robertson

The current version of PL/SQL Developer (11.0.x) has a button to disable/enable substitution variables.

当前版本的 PL/SQL Developer (11.0.x) 有一个按钮来禁用/启用替换变量。

enter image description here

在此处输入图片说明

回答by APC

One of the features of PL/SQL Developer which it takes time to get familiar with is the plethora of different window types.

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 DEFINEand indeed SET SCAN OFFwork in that window.

其中之一是 COMMAND 窗口,它基本上是一个 SQL*Plus 模拟器。我们可以运行 SQL*Plus 命令以及 SQL,所以SET ESCAPESET DEFINE并且确实SET SCAN OFF在该窗口中工作。

回答by Aitor

Have you tried something like this?

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

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

Improving my first answer, your problem is related with PL/SQL Developer. If you execute your block in a PL/SQL Developer Command window, you could also use the standard SET DEFINE OFF, which works the same as in SQL*Plus.

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

回答by NSC

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

concat 对我来说非常好,下面是我在 select 语句中所做的:

select FUND_NM
FROM PERFORMANCE
WHERE upper(FUND_DESC) in ('My L&' ||'L FUNDS')

回答by mason

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

chr(38)在 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';

回答by Saurabh Srivastava

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.

这只是一个 SQL 编辑器问题。要解决这个问题,只需使用 SET DEFINE OFF 编译程序;. PL(在服务器中执行)的执行不会面临这个问题。