PL/SQL的loop循环

转载自网易博客http://blog.163.com/xuejelly1985@126/blog/static/362103402008823101415479/

1、for--loop循环

declare
 s_no student.sno%type;
cursor c1 is
 select sno from student where sno>'10001';
begin
for i  in c1 loop
dbms_output.put_line(i.sno);
end loop;
end;
/
--游标的FOR循环,在FOR循环中,是隐含的自带游标的打开和关闭。

2、loop--end loop循环

declare
 s_no student.sno%type;
cursor c1 is
 select sno from student where sno>'10001';
begin
 open c1;
loop
  fetch c1 into s_no;
exit when c1%notfound;
dbms_output.put_line(s_no);
end loop;
close c1;
exception
 when no_data_found then
   dbms_output.put_line('no data1');
end;
/
--一般的LOOP循环,要显示的打开和关闭游标,而且要特别的注意循环条件的退出与输出的前后关系。

3、if判断

declare
   cursor c1 is
 select sno from student where sno>'10001';
begin
for i  in c1 loop
if(i.sno<10004) then
dbms_output.put_line(i.sno);
end if;
end loop;
end;
/
--一种简单的条件判断。


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值