oracle 中退出循环的用法

来源:互联网 发布:广东省干部培训网络学 编辑:程序博客网 时间:2024/05/16 14:40

declare
  i integer;
  j integer;
begin
  i := 1;
  j := 1;
  <<main_loop>>
  for i in 1 .. 10 loop
                            ---主循环---
    for j in 1 .. 10 loop
                            ---次循环---
      exit main_loop when i=2;
     
      if j = 3 then
        exit;               ---退出当前循环---
      end if;
      if i = 5 then
        exit main_loop;      ---退出主循环---
      end if;
      /*
          exit main_loop when i=5;         
      */
     
      dbms_output.put_line('j的值为' || j);
    end loop;               ---次循环结束---
 
    dbms_output.put_line(i);
 
  end loop main_loop; ---主循环结束---
exception
  when others then
    dbms_output.put_line(sqlerrm);
end;