oracle loop 次数,Oracle中的loop循环实现方式

--loop ...exit; when ...end loop; 大于2000的薪资

--select * from emp where emp.sal>2000  ;

declare

temp_salary emp.sal%type; --%type:通常是指某行某列数据类型 一个字段

temp_emp emp%rowtype; --%rowtype:通配一行所有列的数据类型 如v_row_test%rowtype;匹配emp表中的一行数据

cursor mycursor is ---游标(cursor)

select * from emp where emp.sal>temp_salary;

begin

temp_salary:=2000;

open mycursor;

loop

fetch mycursor into temp_emp;

exit when mycursor%notfound;--找不到数据时

dbms_output.put_line('ename:'||temp_emp.ename||'薪资'||temp_emp.sal);

end loop;

end;

----- for i in 1...n loop...end loop;

declare

temp_emp  emp%rowtype;

cursor cur is select * from emp    where emp.sal>2000;

begin

if cur%isopen=false then --判断游标是否打开

open cur;

end if;

for i in 0..6 loop

fetch cur into temp_emp;

exit when cur%notfound;

dbms_output.put_line('ename:'||temp_emp.ename||' ,sal:'||temp_emp.sal);

end loop;

close cur;

end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值