当前位置: 首页 > 工具软件 > goto > 使用案例 >

oracle goto用法

陶烨赫
2023-12-01

oracle中goto一般用在循环当中。作用类似于continue,看下面代码

create or replace procedure test is
  i integer;
begin
  i := 0;
  loop
    <<next_step>>
    i := i * 2;
    if i > 100 then
      exit;
    end if; 
    if i > 50 then
      goto next_step;
    end if;
    dbms_output.put_line(i);
  end loop;
end; 

dbms_output:打印日志到控制台
1 <<next_step>>:这是循环标签,next_step是名字,可以自己定义。
2 goto next_step:表示i>50后继续走到标签所在的位置执行代码。
3. 特别注意:<<next_step>> 后面不能跟EXCEPTION、END LOOP这种关键字类的语句,要用NULL把标签跟关键字隔开。

 类似资料: