Oracle 自定义异常

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_28061489/article/details/79619167
/*自定义异常:如果你想在某个特定时间发生时间向应用程序的用户发出一些警告信息。
而事件本身不会抛出Oracle内部异常,这个异常是属于应用程序的特定异常,那么就需要自定义异常

用户定义的异常错误是通过显式使用raise语句来触发,当引发一个异常错误时,控制就转向到exception块
异常错误部分,执行错误处理代码
步骤:
  1.在声明部分定义异常  <异常情况> exception;
  2.raise <异常情况>
  3.异常情况处理部分对异常情况作出相应的处理
*/
declare
  v_empno emp.empno%type:=&empno;
  ex_result exception;
begin
  update emp set sal = sal + 100 where empno = v_empno;
  if sql%notfound then
    raise ex_result;
  else
    commit;
  end if;
  exception
    when ex_result then
      dbms_output.put_line('数据更新失败!');
      rollback;
    when others then
      dbms_output.put_line('其他异常!');
end;

猜你喜欢

转载自blog.csdn.net/qq_28061489/article/details/79619167
今日推荐