sql pls-00103代码错误

时间:2014-11-15 01:55:14

标签: sql oracle

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的行时删除该行。

1 个答案:

答案 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条件的意图。