在这里,我向我们展示了当我试图查看触发器是否有效时会发生什么。 我有2个表:contracts_aux和匹配。
团队是从0到9的NUMBER(1)。
MATCHES中的属性团队必须与合同中的此玩家相同或少于或少于1。 (在比赛中,同一个玩家可能会出现不止一次)。
SQL> select * from contracts_aux;
PLAYER TEAM
-------------------- ----------
Peter 5
Mark 7
SQL> select * from matches;
PLAYER TEAM MATCH
-------------------- ---------- ----------
Peter 5 99
Peter 4 92
SQL> insert into matches values ('Peter',1,41);
insert into matches values ('Peter',1,41)
*
ERROR at line 1:
ORA-20000: error jeje
ORA-06512: at "SYSTEM.MATCHES_BIU_TEAM", line 12
ORA-04088: error during execution of trigger 'SYSTEM.MATCHES_BIU_TEAM'
我得到了那个错误。
触发器是:
CREATE TRIGGER MATCHES_BIU_TEAM
BEFORE INSERT OR UPDATE OF team on matches
FOR EACH ROW
DECLARE
nContract_count NUMBER;
BEGIN
SELECT COUNT(*)
INTO nContract_count
FROM CONTRACTS_aux c
WHERE c.PLAYER = :NEW.PLAYER AND
c.TEAM BETWEEN :NEW.TEAM - 1
AND :NEW.TEAM + 1;
IF nContract_count = 0 THEN
RAISE_APPLICATION_ERROR(-20000,'error jeje');
END IF;
END MATCHES_BIU_TEAM;
/
我不知道为什么会出现这个错误..