我是否必须打开游标才能使用隐式游标的 %FOUND 或 %NOTFOUND 游标属性?
是否可以在以下 FOR 循环之后执行 c_emp%notfound
还是我必须先打开游标?
declare
cursor c_emp is select * from employee;
begin
for c_rec in c_emp
loop
dbms_output.put_line(r_emp.first_Name);
end loop;
end;
/
我想在 FOR 循环之后执行一个 UPDATE 语句,但前提是 FOR 循环确实处理了游标上的任何行。我知道我可以设置一个标志,但是有更干净的方法吗?
Is it possible to execute c_emp%notfound
after the following FOR loop or do I have to open the cursor first?
declare
cursor c_emp is select * from employee;
begin
for c_rec in c_emp
loop
dbms_output.put_line(r_emp.first_Name);
end loop;
end;
/
I want to execute a statement a single UPDATE statement after the FOR loop but only if the FOR loop did process any of the rows on the cursor. I know i can set a flag but is there a cleaner way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,这会抛出
ORA-01001:无效游标
。游标属性仅在游标打开时才具有作用域,在此语法中位于FOR
和END LOOP
这是 PL/SQL 的一个丑陋的方面,但恐怕您会陷入计数困境。
No, that's going to hurl
ORA-01001: invalid cursor
. The cursor attributes only have scope while the cursor is open, which in this syntax is between theFOR
and theEND LOOP
.This is an ugly aspect of PL/SQL but I'm afraid you're stuck with a count.
为什么不只是:
我在这里假设您的员工表有一个名为 ID 的主键,您可以根据需要进行调整。
Why not just:
I assume here the your employee table has a primary key called ID, you can adjust as needed.