如何修复“不允许新的或旧的引用”?

时间:2019-01-09 10:01:57

标签: oracle plsql database-trigger

我试图在触发器中使用新旧引用,但我不知道如何解决问题。

CREATE OR REPLACE TRIGGER verifcomglob

AFTER UPDATE OF COMETAT on COMMANDE
REFERENCING NEW AS NEW


DECLARE
  V_COMGLOB numeric;
  V_COMPROD P.PRODNUM%TYPE;
   CURSOR C_COMPROD IS
          SELECT P.PRODNUM
          FROM COMMANDE CM, COMMANDEGLOBALE CGN, PRODUIT P, CONCERNERGLOB CG, CONCERNER C
          WHERE CM.COMNUM = C.COMNUM
          AND C.PRODNUM = P.PRODNUM
          AND P.PRODNUM = CG.PRODNUM
          AND CG.COMGLOBNUM = CGN.COMGLOBNUM
          AND CGN.COMGLOBETAT = 'en constitution'
          AND CM.COMNUM=:new.COMNUM;

  CURSOR C_COMGLOB IS
          SELECT CGN.COMGLOBNUM
          FROM COMMANDE CM, COMMANDEGLOBALE CGN, PRODUIT P, CONCERNERGLOB CG, CONCERNER C
          WHERE CM.COMNUM = C.COMNUM
          AND C.PRODNUM = P.PRODNUM
          AND P.PRODNUM = CG.PRODNUM
          AND CG.COMGLOBNUM = CGN.COMGLOBNUM
          AND CGN.COMGLOBETAT = 'en constitution'
          AND P.PRODNUM=V_COMPROD
          AND CM.COMNUM=:new.COMNUM;

BEGIN
    OPEN C_COMPROD;
    LOOP
    FETCH C_COMPROD INTO V_COMPROD ;
        OPEN C_COMGLOB;
        LOOP
        FETCH C_COMGLOB INTO V_COMGLOB ;
        if(C_COMGLOB%ROWCOUNT) != 0   THEN
        UPDATE CONCERNERGLOB SET CONCERNERGLOB.qtecom = (CONCERNERGLOB.qtecom + (SELECT CONCERNER.QTECOM FROM CONCERNER, COMMANDE where COMNUM=:new.COMNUM AND PRODNUM=V_COMPROD)) WHERE CONCERNERGLOB.COMGLOBNUM=V_COMGLOB AND CONCERNERGLOB.PRODNUM=V_COMPROD;
        ELSE
        null;
        end if;
        END LOOP;

    END LOOP;

CLOSE C_COMGLOB ;
END;

这是Oracle错误:

  
      
  1. 00000-“表级触发器中不允许使用NEW或OLD引用”
      *原因:触发器正在访问表触发器中的“新”或“旧”值。
      *操作:删除所有新旧参考。
  2.   

1 个答案:

答案 0 :(得分:0)

您正在创建一个语句级触发器,该触发器无法访问各个行。

您显然想要一个行级触发器,因此您需要这样声明:

CREATE OR REPLACE TRIGGER verifcomglob
   AFTER UPDATE OF COMETAT on COMMANDE
   REFERENCING NEW AS NEW
   FOR EACH ROW --<< here
....