CREATE OR REPLACE TRIGGER verifier_salle_pavillon
AFTER INSERT OR UPDATE ON Salle
FOR EACH ROW
BEGIN
IF (:NEW.id_salle = (select *
from Salle
where id_pavillon = :OLD.id_pavillon;))
THEN
DELETE FROM Salle
WHERE id_salle = :NEW.id_salle;
END IF;
END;
/
我得到了这个错误:
4/42 PLS-00103: Encountered the symbol ";" when expecting one of the
following:
. ( ) * @ % & - + / at mod remainder rem with <exposant (**)>
and or group having intersect minus start union where connect
|| indicator multiset
The symbol ";" was ignored.
错误在第4行? BEGIN有什么问题?
该触发器有什么问题? 我只想在已经有一行具有相同id_pavillon和id_groupe的行时删除该行。
答案 0 :(得分:1)
解析问题是这部分中的分号:
IF (:NEW.id_salle = (select *
from Salle
where id_pavillon = :OLD.id_pavillon;))
--------------------------------------------------------^
我应该说“第一个问题”。代码= (select *
非常不正统,很可能会产生错误。
您可以在没有if
:
DELETE FROM Salle
WHERE id_salle = :NEW.id_salle AND
EXISTS (SELECT 1 FROM Salle WHERE id_pavillon = :OLD.id_pavillon);
这可能需要另一个条件,具体取决于原始if
条件的意图。