oracle自定义异常

1.弹出错误框:

示例代码:

declare 
v_count number;
begin 
  select count(*) into v_count from dept;
  if v_count < 10 then 
    raise_application_error(-20001,'数量小于10');
  end if;
end;

执行结果:

 

2.控制台显示:

示例代码:

declare 
v_count number;
my_exp exception;
begin 
  select count(*) into v_count from dept;
  if v_count < 10 then 
    raise my_exp;
  end if;
  exception 
    when my_exp then 
      dbms_output.put_line('数量小于10');
    when others then 
      dbms_output.put_line('其他异常');
end;

执行结果:

 

posted on 2016-04-06 09:32  星东烁  阅读(1933)  评论(0编辑  收藏  举报

导航