plsql中异常的传递

begin
  declare
    v_name varchar2(2) := 'ABC';
  begin
    dbms_output.put_line(v_name);
  exception
    when others then
      dbms_output.put_line('xxx');
  end;
exception
  when others then
    dbms_output.put_line('rrrrrr'||sqlcode || sqlerrm);

end;

声明区域的异常,直接是传递到了最外层

rrrrrr-6502ORA-06502: PL/SQL: 数字或值错误 :  字符串缓冲区太小


在异常中恢复,将异常的处理放到子块中,这样在处理完异常后,可以继续进行下面的语句操作。

declare
  e_duplicate_name exception;
  v_name    emp.ename%type;
  v_newname emp.ename%type := 'smith';
begin
  begin
    select ename into v_name from emp where empno = 123;
    if v_name = v_newname then
      raise e_duplicate_name;
    end if;
  exception
    when e_duplicate_name then
      v_newname = 'jack';
  end;
  insert into emp values (123, v_newname);
exception
  when others then
    dbms_output.put_line(sqlcode || sqlerrm);
end;


获取异常程序的位置,在oracle10g后,有dbms_utility.format_error_backtrace,可以用来跟踪堆栈

 when others then
    dbms_output.put_line(sqlcode || sqlerrm||dbms_utility.format_error_backtrace);
end;



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值