游标(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