oracle存储过程continue

在编写存储过程的过程中需要用到类似于Java循环中continue的功能,但是发现开发环境数据库安装的是oracle 10g并不支持continue语句,现场的测试库和正式库都是使用的11g,11g是支持continue语句的。exit用来跳出循环,并不能到下一次循环。return跳出存储过程

 查看oracle的版本信息 :用客户端连接到数据库,执行select * from v$instance 查看version项。
 

 这样在本地测试就需要单独编写一版存储过程,oracle 10g及以下使用goto来替代continue

begin
    for i in 1..10 loop
      if mod(i,2)=0 then
        goto reapt point;
      end if;
      dbms_output.put_line(i); 
      <<reapt point>> ----要英文的两个尖括号
      null;
    end loop;
  end;
<<reapt point>>标签后的null;语句不可少,因为goto标签后必须紧接着一个执行语句 
或者自定义一个excption 来处理

begin
   loop
  exit when ...
  declare
   ex exception;
  begin
    if .. then
    raise ex;
   end if;
  exception
    when ex then
     null;
  end;
...
end loop;
end;


而正式环境只需要使用continue即可

begin
    for i in 1..10 loop
      if mod(i,2)=0 then
        continue;
      end if;
      dbms_output.put_line(i); 
         end loop;
  end;



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值