create or replace procedure add_user is cursor cur is select * from a_user where rownum < 10; l_user a_user%rowtype; begin -- open cur; //报错, 游标已打开 for l_user in cur -- 游标自动打开 loop dbms_output.put_line(l_user.username); end loop; -- 游标自动关闭 --close cur; //报错,无效的游标 end; create or replace procedure add_user is cursor cur is select * from a_user where rownum < 10; l_user a_user%rowtype; begin open cur; loop exit when cur%notfound ; fetch cur into l_user; dbms_output.put_line(l_user.username); end loop; close cur; end;
oracle 游标使用 二
本文详细介绍了在PL/SQL中如何正确地使用游标进行数据处理。通过对比两种不同的游标使用方式,展示了利用循环和FETCH语句来遍历游标的正确方法,并解释了为何某些操作会导致错误。

被折叠的 条评论
为什么被折叠?



