gpt4 book ai didi

oracle - 提取后%NOTFOUND可以返回null吗?

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

This question提出了一个非常有趣的观点;在Oracle文档中,关于在获取后%NOTFOUND是否可能为null似乎存在矛盾。是吗?

引用11g documentation

Note: In Example 6-16, if FETCH never fetches a row, then c1%NOTFOUND is always NULL and the loop is never exited. To prevent infinite looping, use this EXIT statement instead: EXIT WHEN c1%NOTFOUND OR (c1%NOTFOUND IS NULL);



该文档似乎直接自相矛盾,因为它也表示以下内容,这意味着在获取 %NOTFOUND之后不能为空。

%NOTFOUND (the logical opposite of %FOUND) returns:
NULL after the explicit cursor is opened but before the first fetch
FALSE if the most recent fetch from the explicit cursor returned a row
TRUE otherwise



10g documentation也有类似的警告,这不一定是直接的矛盾,因为它警告为获取此行为可能无法成功执行获取操作。

Before the first fetch, %NOTFOUND evaluates to NULL. If FETCH never executes successfully, the EXIT WHEN condition is never TRUE and the loop is never exited. To be safe, you might want to use the following EXIT statement instead:

EXIT WHEN c1%NOTFOUND OR c1%NOTFOUND IS NULL;



在什么情况下,执行获取后,获取可能会失败,或者 %NOTFOUND返回null?

最佳答案

我发现一种提取可能失败的情况:

declare
i integer;
cursor c is
select 1 / 0 from dual;
begin
open c;

begin
fetch c
into i;
exception
when others then
dbms_output.put_line('ex');
end;

if c%notfound is null then
dbms_output.put_line('null');
elsif c%notfound then
dbms_output.put_line('true');
else
dbms_output.put_line('false');
end if;
close c;

end;

但这只会使您的问题更强,因为无论在10g还是11g中,它都将评估为null……

关于oracle - 提取后%NOTFOUND可以返回null吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11273185/

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