触发器的异常处理

上上周,帮别人调试存储过程,触发器中的异常处理没有进行处理。把代码贴出来。
create or replace trigger TRG_test
before insert or delete or update on user
for each row
DECLARE
Table_name varchar(255);
begin
select TABLE_NAME into Table_name from user_triggers where TRIGGER_NAME='TRG_test';
begin
update nc set deletetime = to_char(sysdate,'yyyy-mm-dd hh24:mi:ss')
where id=Table_name;
exception
when others then
DBMS_OUTPUT.PUT_LINE('delete');
end;
end if;
if UPDATING then
begin
update nc set updatetime = to_char(sysdate,'yyyy-mm-dd hh24:mi:ss')
where id=Table_name;
exception
when others then
DBMS_OUTPUT.PUT_LINE('update');
end;
end if;
exception
when others then
DBMS_OUTPUT.PUT_LINE('EXCEPTION');
end;
delete或update的时,出现异常时,并没有打印‘delete’或‘update’,不知道为什么,于是加一个参数判断是否存在这条记录,如果不存在再插入,简略的实现
 select count(*) into countN from nc where id = Table_name;
if countN >1 then
update……
end if;

另外触发器一般不能用commit和rollback语句,除非声明事务,加上
pragma   autonomous_transaction;
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值