存储过程-cursor

-----存储过程游标使用篇-----
-- 1.隐式游标 : 隐式Cursor是系统自动打开和关闭Cursor.
--SQL%ROWCOUNT 整型 代表DML语句成功执行的数据行数
--SQL%FOUND  布尔型  值为TRUE代表插入、删除、更新或单行查询操作成功
--SQL%NOTFOUND 布尔型 与SQL%FOUND属性返回值相反
--SQL%ISOPEN 布尔型 DML执行过程中为真,结束后为假
begin
  update student set s_name = 'modify' where s_id = 4; 
  if(sql%found) then
    Dbms_Output.put_line('find the rowdata 。。。');
    commit;
    else
    Dbms_Output.put_line('unfind the rowdata 。。。');
    rollback;
  end if;
end;
-- 2.显示游标
declare
  cursor cur is select * from student;
  cursor cur2 is select * from student;
  stuRow student%rowtype;
begin
  for stu in cur loop
    --stuRow := stu;
    Dbms_Output.put_line(stu.s_name);
  end loop;
 
  open cur2;
  loop
    Fetch cur2 into stuRow;
    Exit when cur2%notfound;
    Dbms_Output.put_line(stuRow.s_name);
  end loop;
  Dbms_Output.put_line(cur2%ROWCOUNT);
  if(cur2%isopen) then
    Dbms_Output.put_line('-close cur2-');
    close cur2;
  end if;
end;
-- 3.动态游标
declare
  type cursor_type is ref cursor;
  cur cursor_type;
  sqlStr varchar2(40);
  rowData student%rowtype;
begin
  sqlStr := 'select * from student';
  open cur for sqlStr;
  loop
    fetch cur into rowData;
    if(cur%notfound) then
      exit;
      Dbms_Output.put_line('-not find ...-');
    end if;
    Dbms_Output.put_line('-data-'||rowData.s_name);
  end loop;
  if(cur%isopen) then
   close cur;
  end if;
end;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值