1、oracle-游标cursor、存储过程

静态游标和REF游标,静态游标分为:显示游标/隐式游标
显示游标使用步骤:声明游标,打开,读取,关闭
declare cursor cursor_name
open cursor_name
fetch cursor_name into record_name
close cursor_name

declare
cursor my_test is select * from SF_OPERATORLOG;
row_record SF_OPERATORLOG%rowtype; (声明类型,或者varchar(20),oid%type)
begin
open my_test;
fetch my_test into row_record;
dbms_output.put_line(row_record.oid||'%$%'||row_record.tablename);
close my_test;
end;

对于fetch要执行多条语句操作时,添加loop/end loop;

declare
cursor my_test is select name,type from user_source;
row_oid user_source.name%type;
row_tablename user_source.type%type;
begin
open my_test;
loop
fetch my_test into row_oid,row_tablename;
exit when my_test%notfound;
dbms_output.put_line(row_oid||'%$%'||row_tablename);
end loop;
close my_test;
end;

使用fetch...into...是单条数据提取,
使用fetch...bulk collect into + for进行批量提取
declare
cursor my_test is select * from user_source;
type tab is table of user_source%rowtype;
row_record tab;
begin
open my_test;
loop
fetch my_test bulk collect into row_record ;
for i in 1..row_record.count
loop
dbms_output.put_line(row_record(i).type||'---'||row_record(i).name);
end loop;
exit when my_test%notfound;
end loop;
close my_test;
end;
或是用cursor for loop迭代
declare
cursor my_test is select name,type from user_source;
begin
for index1 in my_test
loop
dbms_output.put_line(index1.name||'---'||index1.type);
end loop;
end;
游标的属性
%isopen(true/false) if my_test%isopen then else
%found(true/false) if my_test%found then else
%notfound(true)
%rowcount(int) 当前游标的行数

带参数的游标 191/171
隐式游标SQL 192/172
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值