测试重复健的触发器

create table res_treecomponent_table_dup as select * from res_treecomponent_table where 1= 0;
--用来测试重健的触发器
create or replace trigger bir_test
 before insert on test for each row
declare
 PRAGMA AUTONOMOUS_TRANSACTION;--使用自治事务,才能在触发器中执行commit/rollback;
begin
        dbms_output.put_line('insert me first');
        insert into test2 values(:new.id,:new.name);
	commit;
exception
        when DUP_VAL_ON_INDEX then
                dbms_output.put_line('you have input dup val');
		insert into test_result values(myseq.nextval,to_char(sysdate,'yyyy-MM-dd HH24:mi:ss'),'insert',1);
		commit;
        when others then
                dbms_output.put_line('unknown exception');
		insert into test_result values(myseq.nextval,to_char(sysdate,'yyyy-MM-dd HH24:mi:ss'),'insert',0);
		commit;
end;


 

你可能感兴趣的:(exception,测试,table,input,insert,each)