可以%NOTFOUND在获取后返回null? [英] Can %NOTFOUND return null after a fetch?

查看:218
本文介绍了可以%NOTFOUND在获取后返回null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题提出了一个非常有趣的观点:在Oracle文档中似乎存在一个矛盾,即在提取后是否可能%NOTFOUND 为null。是吗?

This question raised a very interesting point; there seems to be a contradiction in the Oracle documentation on whether it's possible for %NOTFOUND to be null after a fetch. Is it?

引用 11g文档


注意:在示例6-16中,如果FETCH从不提取行,则c1%NOTFOUND
始终为NULL,并且不会退出循环。为了防止无限的
循环,使用这个EXIT语句:EXIT WHEN c1%NOTFOUND OR
(c1%NOTFOUND IS NULL);

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 后不能 null。

The documentation seems to directly contradict itself as it also says the following, which implies that after a fetch %NOTFOUND cannot be null.


%NOTFOUND(与%FOUND逻辑相反)返回:

在显式游标打开后为NULL但在第一次获取之前

FALSE,如果从显式游标的最近一次获取返回了一行

TRUE否则

%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文档有一个类似的警告,这不一定是一个直接的矛盾,因为它警告一个抓取可能无法成功执行,为了展现这个行为。

The 10g documentation has a similar warning, which isn't, necessarily, a direct contradiction as it warns that a fetch might not execute successfully in order for this behaviour to be exhibited.


在第一次提取之前,%NOTFOUND计算为NULL。如果FETCH永不
成功执行,则EXIT WHEN条件永远不为TRUE,并且
循环永不退出。为了安全起见,您可能需要使用以下
EXIT语句:

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或c1%NOTFOUND IS NULL;

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

在什么情况下可能会提取失败或可能%NOTFOUND fetch已执行?

In what situations might a fetch either "fail" or might %NOTFOUND return null after a fetch has been executed?

推荐答案

我可以找到抓取失败的情况:

I can find a situation where a fetch can fail:

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;

但这只会使你的问题更强,因为它将评估为null,无论在10g还是在11g。 ..

But this only makes your question stronger since it will evaluate to null, neither in 10g nor in 11g ...

这篇关于可以%NOTFOUND在获取后返回null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆