触发从另一个表插入值

时间:2017-12-18 19:06:32

标签: plsql triggers insert

我无法使用搜索找到答案。如何使用我创建的触发器从表FK_SOCRD_ID获取列CR_MDT的值以插入表CR_MDT_AUDIT

CREATE OR REPLACE TRIGGER  "CR_MDT_AUDIT" 
before insert or delete or update on CR_MDT
for each row 
declare 
  V_user varchar2 (30);
  V_date varchar2 (30); 
begin 
  IF inserting THEN
     insert into CR_MDT_AUDIT (new_value, OLD_VALUE, user_name, entry_date, operation, FK_SOCRD_ID)
     VALUES (:NEW.CR_MDT_ABSTRACTOR_DT, NULL, v_user, v_date, 'Abstraction Completed');
  ELSIF DELETING THEN
     insert into CR_MDT_AUDIT (new_value, OLD_VALUE, user_name, entry_date, operation, FK_SOCRD_ID)
     VALUES (null, :OLD.CR_MDT_ABSTRACTOR_DT, v_user, v_date, 'delete');
  ELSIF UPDATING THEN
     insert into CR_MDT_AUDIT (new_value, OLD_VALUE, user_name, entry_date, operation, FK_SOCRD_ID)
     VALUES (:NEW.CR_MDT_ABSTRACTOR_DT, :OLD.CR_MDT_ABSTRACTOR_DT, v_user, v_date, 'Update');
  END IF;
END;

我不知道要使用哪个条款或措辞,以便FK_SOCRD_ID的{​​{1}}值添加到CR_MDT表。基本上,我试图找到一种方法来确定改变的位置。

0 个答案:

没有答案