触发器约束错误sql oracle?

时间:2012-03-05 16:59:16

标签: sql oracle triggers constraints

尝试编译以下触发器时出错...

CREATE OR REPLACE TRIGGER DegreePart_CreditsMax
BEFORE INSERT OR UPDATE ON DEGREE_MODULE
FOR EACH ROW
BEGIN
IF(SUM(NUMBER_OF_CREDITS) FROM DEGREE_MODULE INNER JOIN MODULE ON DEGREE_MODULE.MODULE_ID = MODULE.MODULE_ID
        WHERE OPTIONAL = 'N' AND DEGREE_ID = :NEW.DEGREE_ID > 120)
THEN
RAISE_APPLICATION_ERROR( -- Error Message
-20001, 
'Degree must not contain compulsary modules worth over 120 credits.' );
END IF;
END;
/

我正在尝试检查当添加一个模块时,该学位的所有当前必修模块加上新模块的总和小于120 ???

错误是......

  

错误(2,27):PLS-00103:当期待以下之一时遇到符号“FROM”:),*& = - +< /> at in mod mod not rem => <>或!=或〜=> =< =<>和/或喜欢喜欢喜欢的喜欢...之间的|| multiset成员submultiset

1 个答案:

答案 0 :(得分:0)

你可以尝试'改写'这样的条件:

IF EXISTS (
  SELECT SUM(NUMBER_OF_CREDITS)
  FROM DEGREE_MODULE
    INNER JOIN MODULE ON DEGREE_MODULE.MODULE_ID = MODULE.MODULE_ID
  WHERE OPTIONAL = 'N' AND DEGREE_ID = :NEW.DEGREE_ID
  HAVING SUM(NUMBER_OF_CREDITS) > 120
)
THEN
  …