Oracle中的loop循环的例子

第一:loop... exit when...end loop;

declare
temp_salary employee.salary%type;
temp_emp employee%rowtype;
cursor mycursor is 
select * from employee where employee.salary>temp_salary;
begin
temp_salary:=2000;
open mycursor;
loop 
fetch mycursor into temp_emp;
exit when mycursor%notfound;
dbms_output.put_line('编号:'||temp_emp.empid||','||'名字:'||temp_emp.empname||','||'薪水:'||temp_emp.salary);
end loop;
end;

 output:

编号:13,名字:aaa,薪水:2440
编号:10,名字:dwj,薪水:2140
编号:12,名字:eee,薪水:2140

 

loop

statament1;

exit when condition;

statament2;

end loop;

 

第二:for i in 1...n loop...end loop;

declare
temp_emp employee%rowtype;
cursor cur2 is select * from employee where employee.salary>2000;
begin
if cur2%isopen = false then
open cur2;
end if;
for i in 0..3 loop
fetch cur2 into temp_emp;
exit when cur2%notfound;
dbms_output.put_line('编号:'||temp_emp.empid||','||'名字:'||temp_emp.empname||','||'薪水:'||temp_emp.salary);
end loop;

close cur2;
end;

 output:

编号:13,名字:aaa,薪水:2440
编号:10,名字:dwj,薪水:2140
编号:12,名字:eee,薪水:2140

 

for i in 0...n loop

statement1;

exit when condition;

statament;

end loop;

 

备注:此例子的代表性不强...不过可以初步了解loop的功能。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值