[英]Create trigger to insert After Update the table
Create a trigger named trigger_contact_af_update
that is triggered whenever the contact
table is updated. 创建一个名为
trigger_contact_af_update
的触发器,每当contact
表更新时将触发该触发器。 This trigger will insert the org_name and action into the table contact_log_history
after the update of contact details. 更新联系人详细信息后,该触发器将把org_name和操作插入到表
contact_log_history
。 The action name in the affected log table contact_log_history
is 'After_Update_Contact'
. 受影响的日志表
contact_log_history
的操作名称为'After_Update_Contact'
。
Hints: 提示:
The table structure of contact_log_history
is as follows: contact_log_history
的表结构如下:
org_name Varchar(30)
action Varchar(30)
I wrote the below trigger but no error or trigger created. 我编写了以下触发器,但未创建错误或触发器。
CREATE OR REPLACE TRIGGER trigger_contact_af_update AFTER UPDATE
ON contact_log_history FOR EACH ROW
DECLARE
org_name VARCHAR(30);
action VARCHAR(30);
BEGIN
if (:new.action == 'After_Update_Contact')
then
INSERT INTO contact_log_history (org_name, action)
values (:new.org_name, :new:action);
end if ;
END;
You should use 你应该用
SHOW ERRORS
or 要么
select * from user_errors;
to check the errors during compilation for procedures/functions/triggers. 在程序/功能/触发器的编译过程中检查错误。
Here's a working trigger after fixing the issues and avoiding the variables. 在解决问题并避免使用变量之后,这是一个工作触发器。
CREATE OR replace TRIGGER contact_af_update AFTER
UPDATE
ON contact FOR EACH ROW
DECLARE
BEGIN
IF (:new.action = 'After_Update_Contact') THEN
INSERT INTO contact_log_history
(
org_name,
action
)
VALUES
(
:new.org_name,
:new.action
);
END IF ;
END;
/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.