正在为shipment_status_af_update创建Oracle触发器



我需要创建一个名为"shipment_status_af_update"的触发器,每当更新shipment_sttatus表时就会触发该触发器。此触发器将在更新shipment_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;
/

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

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

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>

最新更新