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;
I'm trying to create a trigger to use on an update operation but am getting the following errors:
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
My guess is that you want to check the :new.quantity_in_stock
and :new.reorder_point
values. And remember that the :new
and :old
pseudo-records are prefixed with colons.
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;
Two things -
Don't forget the ":" before old and new.
you don't need to write the table name.
:old.product.product_id can be changed to :old.product_id
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.