问题是我有以下触发器来观察我的特定列“已更改”,如果它已更新为1我希望它将同一行和“CHANGED_DATE”列更新为当前的SYSDATE。由于某种原因,我一直得到这个错误任何帮助将不胜感激。
UPDATE "SYSADM"."SHIP_CALENDAR" SET CHANGED = '1' WHERE ROWID = 'AABCxCAAEAAAKYEAAB' AND ORA_ROWSCN = '6165377066'
ORA-04091: table SYSADM.SHIP_CALENDAR is mutating, trigger/function may not see it
ORA-06512: at "SYSADM.SHIP_CALENDAR_CHANGED", line 5
ORA-04088: error during execution of trigger 'SYSADM.SHIP_CALENDAR_CHANGED'
create or replace TRIGGER SHIP_CALENDAR_CHANGED
AFTER UPDATE
OF CHANGED
ON SHIP_CALENDAR
REFERENCING OLD AS o NEW AS n
FOR EACH ROW
DECLARE
BEGIN
-- UPDATE SHIP CALENDAR SET UPDATE_CHANGE TO SYSDATE IF CHANGED CHANGES
IF :n.CHANGED = '1' then
UPDATE SHIP_CALENDAR
SET CHANGED_DATE = SYSDATE
WHERE SHIPMENT_ID = :o.SHIPMENT_ID;
END IF;
END;
答案 0 :(得分:3)
使用before update
触发器:
create or replace TRIGGER SHIP_CALENDAR_CHANGED
BEFORE UPDATE
OF CHANGED
ON SHIP_CALENDAR
REFERENCING OLD AS o NEW AS n
FOR EACH ROW
DECLARE
BEGIN
-- UPDATE SHIP CALENDAR SET UPDATE_CHANGE TO SYSDATE IF CHANGED CHANGES
IF :n.CHANGED = '1' then
:n.CHANGED_DATE := SYSDATE
END IF;
END;