首页 > 解决方案 > 为 shipping_status_af_update 创建 Oracle TRIGGERS

问题描述

我需要创建一个名为“shipment_status_af_update”的触发器,每当更新 shipping_status 表时就会触发该触发器。此触发器将在更新 shipping_status 详细信息后将名称和操作插入到表“status_log_history”中。受影响的日志表 status_log_history 中的操作名称为“After_Update_Shipment_Status”。

Hints:
Trigger name : shipment_status_af_update
Table name : status_log_history
Field names :name, action
Action  : 'After_Update_Shipment_Status'.
Hint: Add / after the end statement

我的代码是:

CREATE or REPLACE TRIGGER shipment_status_af_update
AFTER UPDATE on shipment_status FOR EACH ROW declare
BEGIN

insert into status_log_history  (name,action) 
values(:new.name,'After_Update_Shipment_Status');

END;
/

结果:警告:触发器创建时出现编译错误。

标签: oracletriggers

解决方案


如果两个表都存在并且包含您在触发器中使用的名称,则代码编译:

SQL> create table shipment_status (name varchar2(20));

Table created.

SQL> create table status_log_history(name varchar2(20), action varchar2(30));

Table created.

SQL> create or replace trigger shipment_status_af_update
  2    after update on shipment_status
  3    for each row
  4  declare
  5  begin
  6    insert into status_log_history (name, action)
  7    values (:new.name, 'After_Update_Shipment_Status');
  8  end;
  9  /

Trigger created.

SQL>

推荐阅读