PL / SQL更新触发错误

时间:2014-04-02 20:56:14

标签: sql oracle plsql triggers syntax-error

create or replace TRIGGER PRODUCT_REORDER_AU
AFTER UPDATE ON PRODUCT
FOR EACH ROW

BEGIN

IF (PRODUCT.QUANTITY_IN_STOCK < PRODUCT.REORDER_POINT)

THEN

INSERT INTO PURCHASE_ORDER
(PO_NO, PO_DATE, PRODUCT_ID, QUANTITY, SUPPLIER_ID)
VALUES
(OLD.PO_NO, NEW.PO_DATE, OLD.PRODUCT.PRODUCT_ID, OLD.PRODUCT.REORDER_QUANTITY, OLD.PRODUCT.SUPPLIER_ID);

END IF;
END;

我尝试创建一个用于更新操作的触发器,但遇到以下错误:

Error(8,1): PL/SQL: Statement ignored
Error(8,13): PLS-00357: Table,View Or Sequence reference 'PRODUCT.QUANTITY_IN_STOCK' not allowed in this context

2 个答案:

答案 0 :(得分:2)

我的猜测是,您要查看:new.quantity_in_stock:new.reorder_point值。请记住,:new:old伪记录以冒号为前缀。

IF (:new.QUANTITY_IN_STOCK < :new.REORDER_POINT)
THEN
  INSERT INTO PURCHASE_ORDER
    (PO_NO, PO_DATE, PRODUCT_ID, QUANTITY, SUPPLIER_ID)
    VALUES
    (:OLD.PO_NO, :NEW.PO_DATE, :OLD.PRODUCT_ID, 
     :OLD.REORDER_QUANTITY, :OLD.SUPPLIER_ID);
END IF;

答案 1 :(得分:1)

两件事 -

  1. 别忘了&#34;:&#34;在新旧之前。

  2. 您不需要写表名 :old.product.product_id可以更改为:old.product_id