1
这是一个简单的例子,因此很容易重现,但重要的是我需要使用into :someVariable from sometable where sometable.somecolumn = :y
基于查询设置变量,然后在BEGIN/END块。 它似乎引用:y
在where
导致它被清除。为什么会发生?BEGIN/END中使用的绑定变量被清除
我更关心为什么会发生这种情况而不是如何解决这个问题。我有自己的设置工作,但它似乎是一个奇怪的副作用。在第一个例子中,我没有声明一个名为:y的新变量,所以我不认为这是变量隐藏的问题。很明显,第二个例子表明我可以设置变量的值,并且将其设置为在该块的范围之外是可见的,这是我期望的,因为变量被声明在块的范围之外。
clear screen;
variable x varchar2(10);
variable y varchar2(10);
exec :y := 'YYY';
BEGIN
select '1' into :x
from dual
where 'YYY' = :y;
END;
/
select :y from dual;
输出显示:Y清零:
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
:Y
--------------------------------
如果我设置为:y与本身的价值被保留:
clear screen;
variable x varchar2(10);
variable y varchar2(10);
exec :y := 'YYY';
BEGIN
select '1' into :x
from dual
where 'YYY' = :y;
:y := :y;
END;
/
select :y from dual;
输出:
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
:Y
--------------------------------
YYY
我不能重现你的问题。您的测试案例似乎按预期工作。 – BobC
@BobC你使用的是什么版本? – AaronLS
版本:12.1.0.2 – BobC