oracle 不能用goto,包体里面不能用goto语句吗?

本帖最后由 bell6248 于 2014-11-10 14:35 编辑

在137和138之间加一行, 并加上"NULL;", 这段代码即可解决,

即:

........

end;

<>

null;

end loop;

..........

举个类似的例子如下:

SQL>

SQL> declare

2     v_name emp.ename%type;

3  begin

4     for i in (select deptno from dept) loop

5

6        begin

7             select ename into v_name from emp where deptno = i.deptno and rownum <= 1;

8

9        exception

10             when no_data_found then

11                  dbms_output.put_line(i.deptno || ' doesn''t exist');

12                  goto next_loop;

13        end;

14

15       <>

16

17     end loop;

18  end;

19  /

declare

v_name emp.ename%type;

begin

for i in (select deptno from dept) loop

begin

select ename into v_name from emp where deptno = i.deptno and rownum <= 1;

exception

when no_data_found then

dbms_output.put_line(i.deptno || ' doesn''t exist');

goto next_loop;

end;

<>

end loop;

end;

ORA-06550: line 17, column 4:

PLS-00103: Encountered the symbol "END" when expecting one of the following:

begin case declare exit for goto if loop mod null raise

return select update while with

<<

close current delete fetch lock insert open rollback

savepoint set sql execute commit forall merge pipe

SQL>

SQL>

SQL> declare

2     v_name emp.ename%type;

3  begin

4     for i in (select deptno from dept) loop

5

6        begin

7             select ename into v_name from emp where deptno = i.deptno and rownum <= 1;

8

9        exception

10             when no_data_found then

11                  dbms_output.put_line(i.deptno || ' doesn''t exist');

12                  goto next_loop;

13        end;

14

15       <>

16       null;

17

18     end loop;

19  end;

20  /

40 doesn't exist

PL/SQL procedure successfully completed

SQL>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值