gpt4 book ai didi

oracle - 这是 PL/SQL 错误吗?

转载 作者:行者123 更新时间:2023-12-04 01:13:30 25 4
gpt4 key购买 nike

下面是一些 PL/SQL 代码的摘录,我认为它展示了一个 PL/SQL 错误:

if guid_ is null then
dbms_output.put_line('guid_ is null: ' || guid_);
end if;

当这些行被执行时,它会打印
guid_ is null: 07D242FCC55000FCE0530A30D4928A21

我在 Oracle 11R2
select * from v$version;

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE 11.2.0.4.0 Production
TNS for IBM/AIX RISC System/6000: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production

我可以使用以下类型和匿名块重现这一点。对不起,长度,但我相信我不能再缩短它了:
create type tq84_t as table of varchar2(32);
/

create type tq84_o as object (
dummy number(1),

not final member procedure clear

) not final;
/

show errors

create type tq84_d under tq84_o (

g varchar2(32),
constructor function tq84_d return self as result,

overriding member procedure clear


);
/
show errors


create package tq84_h as

t tq84_t;

end tq84_h;
/
show errors



create package body tq84_h as
begin

t := tq84_t();
end;
/
show errors

create type body tq84_o as

member procedure clear is begin
null;
end clear;

end;
/

create type body tq84_d as

constructor function tq84_d return self as result is
begin

g := sys_guid;
return;

end tq84_d;

overriding member procedure clear is begin

tq84_h.t.extend;
tq84_h.t(tq84_h.t.count) := g;

g := null;

end clear;

end;
/
show errors


declare

b tq84_o; -- Change to tq84_d ...

guid_ varchar2(32);

begin

b := new tq84_d;

guid_ := treat(b as tq84_d).g;

b.clear;

if guid_ is null then
dbms_output.put_line('guid_ is null: ' || guid_);
end if;


end;
/

drop type tq84_t;
drop type tq84_d;
drop type tq84_o;
drop package tq84_h;

另请注意,当我更改 b tq84_o 时至 b tq84_d ,错误不再发生。

有人可以验证这是否也发生在其他系统上吗?

最佳答案

对我来说这是一个错误。在 IF变量 guid_put_line 的字符串连接不同。 .我觉得奇怪的是,在 b.clear 之前声明is null作品:

declare
b tq84_o; -- Change to tq84_d ...
guid_ varchar2(32);
begin
b := new tq84_d;
guid_ := treat(b as tq84_d).g;

if guid_ is null then
dbms_output.put_line('before clear: guid_ is null: ' || guid_);
end if;

b.clear;

if guid_ is null then
dbms_output.put_line('after clear: guid_ is null: ' || guid_);
end if;
end;
/

输出:
after clear: guid_ is null: 07D43ACB728A2173E054A0481C66CF28

我在从函数返回 GUID 时解决了这个问题:
declare
b tq84_o; -- Change to tq84_d ...
guid_ varchar2(32);
function get_guid
return varchar2 is
begin
return treat(b as tq84_d).g;
end;
begin
b := new tq84_d;
guid_ := get_guid; -- treat(b as tq84_d).g;

if guid_ is null then
dbms_output.put_line('before clear: guid_ is null: ' || guid_);
end if;

b.clear;

if guid_ is null then
dbms_output.put_line('after clear: guid_ is null: ' || guid_);
end if;
end;
/

上面的代码没有进入 if guid_ is null .所以对我来说,这证明了这一点:

这是一个错误。

关于oracle - 这是 PL/SQL 错误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26931856/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com