游标(cursor)是系统为用户开设的一个数据缓冲区,存放SQL语句的执行结果--方法1
declare
type sp_class_user_cursor is ref cursor;
test_cursor sp_class_user_cursor;
u_xingming s_class_user.xingming%type;
u_username s_class_user.username%type;
begin
open test_cursor for select t.xingming,t.username from s_class_user t where t.class_info_id=&no;
loop
fetch test_cursor into u_xingming,u_username;
exit when test_cursor%notfound;
dbms_output.put_line('名字:'||u_xingming||'员工编号:'||u_username);
end loop;
close test_cursor;
end;
--方法2
declare
cursor test_easy_cursor is select t.xingming,t.username from s_class_user t where t.class_info_id=&class_id;
u_xingming s_class_user.xingming%type;
u_username s_class_user.username%type;
begin
open test_easy_cursor;
loop
fetch test_easy_cursor into u_xingming,u_username;
exit when test_easy_cursor%notfound;
dbms_output.put_line('名字:'||u_xingming||'员工编号:'||u_username);
end loop;
close test_easy_cursor;
end;
注意:如果控制台只显示PL/SQL procedure successfully completed
没有结果可以尝试输入set serveroutput on size 10000000
来防止ORA-20000: ORU-10027: buffer overflow, limit of 2000 bytes
本文介绍了两种在Oracle PL/SQL中使用游标的方法。一种是通过声明引用游标并使用循环进行数据处理;另一种则是直接声明游标并进行数据检索。文章提供了具体的代码示例,并针对常见问题给出了解决方案。
515

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



