更新表格时出现这些错误
ORA-04091: table HAMZA.EXPEDITION is mutating, trigger/function may not see it
ORA-06512: at "HAMZA.LIVRAISONFINIE", line 6
ORA-04088: error during execution of trigger 'HAMZA.LIVRAISONFINIE'
以下是使用的表格
远征(Id_Expedition,Date_Livraison);
COMMANDE(Numero_Commande,..);
cmdalivrer(id_cmd,id_etape);
CREATE OR REPLACE TRIGGER livraisonfinie
AFTER UPDATE ON Expedition
FOR EACH ROW
DECLARE
date_liv Expedition.date_livraison%type;
BEGIN
SELECT :NEW.date_livraison INTO date_liv from Expedition;
IF date_liv <> TO_DATE('00/00/00 00:00:00', 'yyyy/mm/dd hh24:mi:ss')
THEN
INSERT INTO Commande (etat) VALUES ('livree');
DELETE FROM cmdalivrer CMD WHERE :NEW.numero_commande=CMD.id_cmd;
DELETE FROM Expedition E WHERE E.date_livraison = date_liv;
END IF ;
END;
/
感谢您的帮助。
答案 0 :(得分:0)
您可以使用复合触发器完成您尝试做的事情:
CREATE OR REPLACE TRIGGER livraisonfinie_compound
AFTER UPDATE ON Expedition
COMPOUND TRIGGER
TYPE DATE_TABLE IS TABLE OF EXPEDITION.DATE_LIVRAISON%TYPE;
tblDates DATE_TABLE;
BEFORE STATEMENT IS
BEGIN
tblDates := DATE_TABLE();
END BEFORE STATEMENT;
AFTER EACH ROW IS
BEGIN
IF :NEW.date_livraison <> TO_DATE('00/00/00 00:00:00', 'yyyy/mm/dd hh24:mi:ss')
THEN
INSERT INTO Commande (etat) VALUES ('livree');
DELETE FROM cmdalivrer CMD WHERE :NEW.numero_commande=CMD.id_cmd;
tblDates.EXTEND;
tblDates(tblDates.LAST) := :NEW.date_livraison;
END IF ;
END AFTER EACH ROW;
AFTER STATEMENT IS
BEGIN
IF tblDates.COUNT > 0 THEN
FOR i IN tblDates.FIRST..tbDates.LAST LOOP
DELETE FROM Expedition E
WHERE E.date_livraison = tblDates(i);
END LOOP;
END IF;
END AFTER STATEMENT;
END livraisonfinie_compound;
You can read further on compound triggers here
祝你好运。