欢迎大家访问我的BLOG,我会多多的出原创文章,希望大家支持我,为我祈祷,让我实现我的三个梦想!再30岁能成为一个名优秀的软件架构师!

抛出exception-RAISE_APPLICATION_ERROR

RAISE_APPLICATION_ERROR

      可能不是很多人知道 RAISE_APPLICATION_ERROR 的用途是什么,虽然从字面上已经猜到这个函数是干什么用的。
      其实 RAISE_APPLICATION_ERROR 是将应用程序专有的错误从服务器端转达到客户端应用程序。
 
      RAISE_APPLICATION_ERROR 的声明:
 
      PROCEDURE RAISE_APPLICATION_ERROR
                                                    ( error_number_in IN NUMBER, error_msg_in IN VARCHAR2);
 
      里面的错误代码和内容,都是自定义的。说明是自定义,当然就不是系统中已经命名存在的错误类别,是属于一种自定义事务错误类型,才调用此函数。
      error_number_in 之容许从 -20000 到 -20999 之间,这样就不会与 ORACLE 的任何错误代码发生冲突。
      error_msg_in 的长度不能超过 2K,否则截取 2K。
触发器例题:
create or replace trigger EquipStockDtl_insdel
after INSERT or DELETE
ON  EquipStockBillDtl
for each row
DECLARE sno1 float;
          sno2 float;
          insert_error exception;
begin
if inserting then
  select    (nvl(:new.stockamount,0))+nvl(e.planamount,0),
            (nvl(e.checkamount,0))
           into sno1,sno2
    from  EquipRequirDtl e where e.pm_rowid=:new.EquReuDtlID;
  if (sno1>sno2)  then
      RAISE insert_error;
  end if;
end if;
  UPDATE  EquipRequirDtl
          SET planamount=nvl(planamount,0)+(nvl(:new.stockamount,0)-nvl(:old.stockamount,0))
          where EquipRequirDtl.pm_rowid=nvl(:new.EquReuDtlID,:old.EquReuDtlID);
  exception
           when insert_error then
                      raise_application_error(-20001,'insert_error');
end;

posted on 2007-03-16 16:13  程序缘  阅读(405)  评论(0)    收藏  举报

导航