for 循环遍历游标简洁

for 循环遍历游标简洁

for 循环遍历游标,不用open、close、fetch,判断游标是否循环完成。

declare
   cursor c_sal is select empno,ename ,sal from scott.emp;
begin
   --隐含打开游标
   for v_sal in c_sal loop
   --隐含执行一个fetch语句
      dbms_output.put_line(to_char(v_sal.empno)||'-'|| v_sal.ename||' is '||to_char(v_sal.sal)) ;
   --隐含监测c_sal%notfound
   end loop;
--隐含关闭游标
end;
/

执行结果

SQL> /

7369-SMITH is 800
7499-ALLEN is 1600
7521-WARD is 1250
7566-JONES is 2975
7654-MARTIN is 1250
7698-BLAKE is 2850
7782-CLARK is 2450
7788-SCOTT is 3000
7839-KING is 5000
7844-TURNER is 1500
7876-ADAMS is 1100
7900-JAMES is 950
7902-FORD is 3000
7934-MILLER is 1300

PL/SQL procedure successfully completed


Executed in 0.011 seconds


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值