plsql(二)--异常

来源:互联网 发布:铝合金和塑钢知乎 编辑:程序博客网 时间:2024/05/29 15:18

--异常捕获

declare a number:=3;
begin
  a:=5/0;
  exception
    when ZERO_DIVIDE then
      dbms_output.put_line('算术异常');
    when others then
      dbms_output.put_line('dd');
end;

--自定义异常

declare a number:=-3;
        b number:=5;
        gd exception; --自定义一个异常
begin
  if a<0 then
    raise gd;
  end if;
  exception
    when gd then
      dbms_output.put_line('滚蛋');
     when others then
       dbms_output.put_line('dd');

end;

--嵌套异常

declare a number:=-3;

        b number:=5;

        gd exception; --自定义一个异常
begin
  begin
    if a<0 then
      raise gd;
    end if;
    exception
      when gd then
        dbms_output.put_line('滚蛋');
       when others then
         dbms_output.put_line('dd');
  end;
  
  a:=5/0;
  exception
    when ZERO_DIVIDE then
      dbms_output.put_line('算术异常');
    when others then
      dbms_output.put_line('dd');
end;
原创粉丝点击