自定义事务错误类型

防止不小心删除了表中某个字段。
create or replace trigger TRI_t_quote_info_TEMP

after update on t_quote_info

for each row

begin

if : old.SCHEDULE_SPEC_MEMO is not null and : old.policy_id=9900 then

if :new.SCHEDULE_SPEC_MEMO is null then

Raise_application_error(-20005,'throw Exception');

end if;

end if;

end;



drop trigger TRI_t_quote_info_TEMP;

注:t_quote_info:表名,

  SCHEDULE_SPEC_MEMO :表中字段名

policy_id:表中字段名

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。




很简单,很实用.

你可能感兴趣的:(自定义事务错误类型)