游标练习(1027)

本文介绍了两种在Oracle PL/SQL中使用游标的方法。一种是通过声明引用游标并使用循环进行数据处理;另一种则是直接声明游标并进行数据检索。文章提供了具体的代码示例,并针对常见问题给出了解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值