设置扫描关闭目的

发布于 2024-12-29 01:13:43 字数 78 浏览 1 评论 0原文

谁能解释一下 SET SCAN OFF 和 SET SCAN ON 的目的是什么?我知道它的目的是禁用替换变量和参数,但我想要一个清晰的解释。

Can anyone please explain what is the purpose of SET SCAN OFF and SET SCAN ON? I know its purpose is to disable substitution variables and parameters, but I want a clear explanation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

-残月青衣踏尘吟 2025-01-05 01:13:43

SET SCAN 已过时,但它用于控制是否应扫描替换参数/变量。 OFF 将阻止扫描参数/变量。

SET DEFINE 替换/扩展了功能,这里有一篇很好的文章:http://shaharear.blogspot.com/2009/01/set-define.html

来自网站

设置定义;

从双选择“&hello”;

如果定义设置为 on 并且 SQL*Plus 查找当前替换
前缀,它要求输入一个字符串。在下面的示例中,
我输入:hasan

输入 hello 的值:已输入此字符串

 old 1: select '&hello' from dual 
 new 1: select 'this string was entered' from dual

这相当于旧的 SET SCAN 的工作方式。基本上你正在控制是否提示替换

SET SCAN is obsolete but it was used to control whether or not it should scan for substitution params/variables. OFF would prevent scanning for params/variables.

SET DEFINE replaces/extends the functionality and a good writeup is here: http://shaharear.blogspot.com/2009/01/set-define.html

From the website

set define on;

select '&hello' from dual;

If define is set to on and SQL*Plus finds the current substitution
prefix, it asks for a string to be entered. In the following example,
I entered: hasan

Enter value for hello: this string was entered

 old 1: select '&hello' from dual 
 new 1: select 'this string was entered' from dual

This is equivalent to how the old SET SCAN would work. Basically you're controlling whether or not to prompt for a substitution

°如果伤别离去 2025-01-05 01:13:43

在 SQL*Plus(以及支持 SQL*Plus 语法的各种其他工具)中,默认情况下,该工具会扫描 SQL 语句以查找替换变量。这允许您创建 SQL*Plus 脚本,使用 SQL*Plus 中定义的变量来执行各种报告任务。

然而,由于替换变量以 & 符号 ('&') 开头,并且不需要提前声明,因此,如果您尝试运行恰好包含 & 符号的 SQL 语句,就会产生问题。例如,如果您的 INSERT 语句恰好包含包含 & 符号的字符串文字,则您不希望 SQL*Plus 预处理该语句。或者,如果我想选择字符串“foo & bar”,

SQL> set scan off;
SQL> ed
Wrote file afiedt.buf

  1* select 'foo & bar' from dual
SQL> /

'FOO&BAR'
---------
foo & bar

但是如果我允许 SQL*Plus 预处理该语句,则文本 '& bar' 被解释为替换变量,系统会提示我输入要在运行时替换的文本

SQL> set scan on
SQL> /
Enter value for bar: some value
old   1: select 'foo & bar' from dual
new   1: select 'foo some value' from dual

'FOOSOMEVALUE'
--------------
foo some value

In SQL*Plus (and various other tools that support SQL*Plus syntax), by default, the tool scans SQL statements looking for substitution variables. This allows you to create SQL*Plus scripts that use variables defined in SQL*Plus for various reporting tasks.

Because substitution variables begin with the ampersand ('&') and need not be declared in advance, however, that creates problems if you are trying to run a SQL statement that happens to include an ampersand. For example, if you've got an INSERT statement that happens to have a string literal that includes an ampersand, you don't want SQL*Plus to pre-process the statement. Or, if I want to select the string "foo & bar"

SQL> set scan off;
SQL> ed
Wrote file afiedt.buf

  1* select 'foo & bar' from dual
SQL> /

'FOO&BAR'
---------
foo & bar

If I allow SQL*Plus to pre-process the statement, however, the text '& bar' is interpreted as a substitution variable and I'm prompted to enter the text to substitute at runtime

SQL> set scan on
SQL> /
Enter value for bar: some value
old   1: select 'foo & bar' from dual
new   1: select 'foo some value' from dual

'FOOSOMEVALUE'
--------------
foo some value
空心空情空意 2025-01-05 01:13:43

SQL>在 SQL 上设置扫描> /输入栏值:某个旧值 1:选择 'foo & bar' from Dual new 1:从 Dual

'FOOSOMEVALUE' 中选择 'foo some value' --------------foo some value

SQL> set scan on SQL> /Enter value for bar: some value old 1: select 'foo & bar' from dual new 1: select 'foo some value' from dual

'FOOSOMEVALUE' --------------foo some value

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文