oracle游标属性

游标的属性:found,not found,rowcount,isopen

1.found:找到记录返回true。
2.not found:没找到记录返回true。
3.rowcount:返回更新的行数。
4.isopen:游标是否打开,这个属性由游标的open和close更新。

--通过游标的属性监控游标的状态
declare
  cursor cu_student is
  select * from students;
  student students%rowtype;
begin
  --声明游标后
  if cu_student%isopen then
    dbms_output.put_line('声明游标后,isopen返回true');
  else
    dbms_output.put_line('声明游标后,isopen返回false');
  end if;
  --打开游标后
  open cu_student;
    if cu_student%isopen then
      dbms_output.put_line('打开游标后,isopen返回true');
    else
      dbms_output.put_line('打开游标后,isopen返回false');
    end if;
  --执行fetch后
    fetch cu_student into student;
        dbms_output.put_line('第一次执行fetch,cu_student%rowcount='||cu_student%rowcount);
    if cu_student%found then
       dbms_output.put_line('打开游标后,found返回true');
    else
      dbms_output.put_line('打开游标后,not found返回false');
    end if; 
  --执行循环后
    loop
      if cu_student%found then
        dbms_output.put_line('loop: cu_student%rowcount=' || cu_student%rowcount);
        fetch cu_student into student;
      else
        dbms_output.put_line('loop: found属性');-- || cu_student%found);
        dbms_output.put_line('loop: 循环结束rowcount=' || cu_student%rowcount);
      end if;
      exit;
    end loop;
  close cu_student;
  if cu_student%isopen then
    dbms_output.put_line('关闭游标后,isopen(true)');-- || cu_student%isopen);
  else
    dbms_output.put_line('关闭游标后,isopen(false)');-- || cu_student%isopen);
  end if;
end;
--结果
声明游标后,isopen返回false
打开游标后,isopen返回true
第一次执行fetch,cu_student%rowcount=1
打开游标后,found返回true
loop: cu_student%rowcount=1
关闭游标后,isopen(false)
PL/SQL procedure successfully completed



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值