oracle - 为什么更新时触发器不触发
问题描述
我开发了一个触发器来为事务表插入历史数据。
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 条记录进行了更新会导致问题。
解决方案
推荐阅读
- sorting - 订购两个具有相同索引的列表
- android - BiometricPrompt 类在 Xamarin Android 中不可用
- javascript - 当模态打开时,如何将焦点设置在模态内部的第一个 TouchableHighlight 组件(或另一个,例如由 ref 给出)上?
- html - 我正在尝试向我的 html 标题添加一个图标,但该图标未显示
- ios - 如何避免应用程序进入后台?
- javascript - 如何从复杂的数组对象结构中获取数据?
- php - 我如何在php中打印数据
- windows-subsystem-for-linux - WSL 上的 Ubuntu 无法启动
- java - 使用 Spring Boot 从数据库中检索列表
- c# - 如果 OnClientClick="return false",LinkButton OnCommand 函数仅在首次单击时触发