如果集合为空,FETCH INTO 不会引发异常,不是吗?
这是我正在尝试调试的一些实际代码:
BEGIN
OPEN bservice (coservice.prod_id);
FETCH bservice
INTO v_billing_alias_id, v_billing_service_uom_id, v_summary_remarks;
CLOSE bservice;
v_service_found := 1;
-- An empty fetch is expected for some services.
EXCEPTION
WHEN OTHERS THEN
v_service_found := 0;
END;
当参数化游标 bservice(prod_id) 为空时,它将 NULL 提取到三个变量中并且不会引发异常。
那么编写这段代码并期望它抛出异常的人都是错误的,对吗?该注释似乎暗示着空获取是预期的,然后它设置一个标志以供以后处理,但我认为这段代码也不可能用空集进行测试。
显然,它应该使用 bservice%NOTFOUND 或 bservice%FOUND 或类似的。
Here is some actual code I'm trying to debug:
BEGIN
OPEN bservice (coservice.prod_id);
FETCH bservice
INTO v_billing_alias_id, v_billing_service_uom_id, v_summary_remarks;
CLOSE bservice;
v_service_found := 1;
-- An empty fetch is expected for some services.
EXCEPTION
WHEN OTHERS THEN
v_service_found := 0;
END;
When the parametrized cursor bservice(prod_id) is empty, it fetches NULL into the three variables and does not throw an exception.
So whoever wrote this code expecting it to throw an exception was wrong, right? The comment seems to imply that and empty fetch is expected and then it sets a flag for later handling, but I think this code cannot possibly have been tested with empty sets either.
Obviously, it should use bservice%NOTFOUND or bservice%FOUND or similar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当参数化游标 bservice(prod_id) 为空时,它会将 NULL 提取到三个变量中,并且不会引发异常。
错误
当 t 为空时,它不会获取任何内容,并且不会覆盖任何值。
那么
,编写这段代码并期望它抛出异常的人都是错误的,对吗? 是
显然,它应该使用 bservice%NOTFOUND 或 bservice%FOUND 或类似的。 是
When the parametrized cursor bservice(prod_id) is empty, it fetches NULL into the three variables and does not throw an exception.
Wrong
When t is empty, it fetches nothing, and does not overwrite any value.
prints
So whoever wrote this code expecting it to throw an exception was wrong, right? Yes
Obviously, it should use bservice%NOTFOUND or bservice%FOUND or similar. Yes
如果您想知道游标是否返回任何结果,请使用 %FOUND 游标属性:
来自 游标属性< /a>
If you want to know if the cursor returned any result, use the %FOUND cursor attribute:
from cursor attributes