Oracle 存储过程中的循环,条件判断,存储过程,游标小结

Oracle 存储过程中的循环,条件判断
for...in...loop
end loop;循环


for x in 1..100 loop
  deal with
end loop;




loop循环
loop
  执行语句
exit when 条件
end loop


while循环
i:=1;
while i<99
Loop
 begin
i:=i+1;
 end;
end loop;




条件判断
1.if...elsif...else...end if


if conditions
then
  consitions result;
elsif xxx and xxx
then
    conditions result;
else
    conditions result;
end if


2.case when end case判断
v_num:=1
case v_num
  when  1 then
   conditions reuslt;
  when 2 then
   conditions result;
   else
null;
end case;


游标cursor
create or replace procedure pro_1(
 checknum in number,
 ref_cursor out sys_refcursor

as
begin
 open ref_cursor for select × from.......
end pro_1;


sys_refcursor 的三个状态属性
%notfound
%found
%roucount 当前游标所指向的行位置


example1:通过游标返回一个结果集并将这个游标遍历输出
create or replace procedure pro_1(
 checknum in number,
 ref_cursor out sys_refcursor

as
begin
  open ref_cursor for select × from.......;
loop 
fetch ref_cursor into t_tmp;
exit when ref_cursor%notfound;
dbms_output.put_line(t_tmp.id);
update  table....
where id=t_tmp.id;
commit;
end loop;
close ref_cursor;
end pro_1;





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值