首页 > 解决方案 > 为什么更新时触发器不触发

问题描述

我开发了一个触发器来为事务表插入历史数据。

Create or replace trigger his_trg
After insert or update
On trans_tb
For each row
Declare
  V_data number;
  V_seq number := seq_name.nextval;
Begin
Select data into v_data from another_tb where key = :new.key;

If (inserting or updating) and nvl(:old.id) != (:New.id)
Insert into his_tb (column1, column2,column3,column4) Values (v_seq,v_data, :new.data1, :new.data2);
End if;

Exception
When others then
Dbms_output.put_line('error');
End;

现在的问题是当我在 trans_tb 中插入新记录并更新新插入的记录时,记录会插入到 his_tb 中。

但是当我更新 trans_tb 上已经插入的记录时,不会在 his_tb 中发生插入

注意:在 trans_tb 中已经创建了 5 条记录后,我为 trans_tb 创建了触发器。我对这 5 条记录进行了更新会导致问题。

标签: oracleplsqltriggers

解决方案


推荐阅读