我试着编写这段代码,但仍然得到代码没有声明的错误:new.code和:old.code是错误的绑定变量'OLD.CODE'!
CREATE OR REPLACE TRIGGER update_1
BEFORE UPDATE OR DELETE OF PROJCODE
ON ASSIGNMENT
FOR EACH ROW
BEGIN
IF UPDATING THEN
UPDATE PRODUCT P
SET P.CODE = :new.CODE
WHERE P.CODE = :old.CODE;
ELSE
DELETE FROM PROJECT WHERE :old.CODE= CODE ;
END IF;
DBMS_OUTPUT.PUT_LINE(CODE);
END;
我怎样解决这个问题?
答案 0 :(得分:0)
您的触发器应该变为:
CREATE OR REPLACE TRIGGER update_1
BEFORE UPDATE OR DELETE ON PROJCODE
REFERENCING new AS new old AS old
FOR EACH ROW
BEGIN
IF UPDATING THEN
UPDATE PRODUCT P
SET P.CODE = :new.CODE
WHERE P.CODE = :old.CODE;
ELSE
DELETE FROM PROJECT WHERE :old.CODE= CODE ;
END IF;
DBMS_OUTPUT.PUT_LINE(CODE);
END;
/