如何为循环缺失控制创建触发器(Oracle sql)

时间:2017-06-16 11:40:22

标签: sql oracle plsql triggers

我创造了

CREATE TRIGGER TRIGGER_CONTROL_ABSENCE_CYCLE
BEFORE UPDATE ON DEPARTMENT
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
BEGIN
  FOR REC IN (
    SELECT D.ID, D.ID_PARENT
    FROM DEPARTMENT D
    START WITH D.ID_PARENT = :NEW.ID
    CONNECT BY PRIOR D.ID = D.ID_PARENT
  )
  LOOP
    IF :NEW.ID_PARENT = REC.ID THEN
      RAISE_APPLICATION_ERROR(-20000, 'Cycle in hierarchies detected');
    END IF;
  END LOOP;
END;

给出错误讯息 [42000] [4098] ORA-04098:触发无效并在验证时导致崩溃

(我不懂英语,所以我通过翻译翻译了它)

0 个答案:

没有答案