什么是%NOTFOUND在cusor属性的默认值? [英] what is the default value of %NOTFOUND in cusor attribute?

查看:239
本文介绍了什么是%NOTFOUND在cusor属性的默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习的PL / SQL游标。我有一个游标属性的问题。什么一个默认值%FOUND %NOTFOUND 中的显性和隐性游标?

I am studying PL/SQL cursors. I have a problem with a cursor attribute. What a default value for %FOUND, %NOTFOUND in implicit and explicit cursors?

我要通过PDF,我发现这句话

I am going through the PDF I found this sentence

LOOP
FETCH c1 INTO my_ename, my_sal, my_hiredate;
EXIT WHEN c1%NOTFOUND;
...
END LOOP;

的第一次提取之前,%NOTFOUND计算为NULL。所以,如果fetch从不执行成功,则循环永远不会退出。这是因为出关时执行语句仅当它的WHEN条件
真正。为了安全起见,请使用以下EXIT语句来代替:

Before the first fetch, %NOTFOUND evaluates to NULL. So, if FETCH never executes successfully, the loop is never exited. That is because the EXIT WHEN statement executes only if its WHEN condition is true. To be safe, use the following EXIT statement instead:

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

如果游标未打开,用%NOTFOUND 引用它提出了 INVALID_CURSOR

If a cursor is not open, referencing it with %NOTFOUND raises INVALID_CURSOR.

推荐答案

在回答你的问题有没有默认值。 %NOTFOUND 是一个变量,即在光标开幕实例化。在这一点上值为null;我想你可以调用这个默认的,如果你想要的。后的第一次提取光标,具体取决于是否返回任何行的值,要么是虚假的真实。关闭游标的变量后不再存在。

In answer to your question there is no "default" value. %NOTFOUND is a "variable" that is instantiated upon the opening of a cursor. The value at that point is null; I guess you could call this the default if you wanted. After the first fetch of a cursor the value will either be true of false depending on whether any rows were returned. After the cursor is closed the "variable" no longer exists.

要在 11gR2的文档报价

%NOTFOUND(共%的人认为逻辑对面)返回:结果
  在显式游标后,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

借助10克文档有演示此有用的表


+----------------+--------+--------------+
|     stage      |  when  | return value |
+----------------+--------+--------------+
| open           | before | exception    |
|                | after  | null         |
| first fetch    | before | null         |
|                | after  | false        |
| next fetch(es) | before | false        |
|                | after  | false        |
| last fetch     | before | false        |
|                | after  | true         |
| close          | before | true         |
|                | after  | exception    |
+----------------+--------+--------------+

但是,确实出现了Oracle文档中直接矛盾。 11g的文件也有类似你所描述的东西是什么。其中的措辞似乎直接反驳上述论断

However, there does appear to be a direct contradiction in the Oracle documentation. The 11g documentation also has something similar to what you've described. The wording of which seems to directly contradict the above assertion

请注意:在例6-16,如果fetch也不把一排,那么c1%NOTFOUND
  始终是NULL和循环永远不会退出。以prevent无限
  循环,使用EXIT语句来代替:出关时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);

借助10克文档是更明确和略有不同的措辞。这不是一个直接的矛盾

The 10g documentation is more explicit and slightly differently worded. This isn't a direct contradiction

的第一次提取之前,%NOTFOUND计算为NULL。如果FETCH从来没有
  成功执行,退出WHEN条件是不正确的和
  循环永远不会退出。为了安全起见,你可能需要使用以下
  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:

出关时C1%NOTFOUND或C%NOTFOUND IS NULL;

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

在一般我会说,这是明智的,信任的文档,写出关时C1%NOTFOUND或C%NOTFOUND IS NULL

In general I would say that it's wise to trust the documentation and write EXIT WHEN c1%NOTFOUND OR c1%NOTFOUND IS NULL.

我不知道在什么情况下抓取不会成功执行; 我问过的问题。若取从不返回一个值,由于锁定等,那么你永远也不会达到code的一部分,以确定它是否失败与否。

I don't know in what situations a fetch would not execute successfully; I've asked the question. If the fetch never returns a value due to locking etc then you'll never reach the part of the code to determine whether it failed or not.

勒Nyffenegger 对某些code他博客是如何%NOTFOUND 工作的很好的解释。

René Nyffenegger has some code on his blog that is a good explanation of how %NOTFOUND works.

这篇关于什么是%NOTFOUND在cusor属性的默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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