Then it's clear, you have a trigger on table Order Inserts that inserts into table Order/
i.e.,
- Your code inserts one or more rows into Table Order, firing trigger.
- trigger executes, and examines on_hand quantity, if sufficient, it
- inserts into table ORDER, firing trigger,
- trigger executes, and examines on_hand quantity, if sufficient, it
- inserts into table ORDER, firing trigger,
- trigger executes, and examines on_hand quantity, if sufficient, it
- inserts into table ORDER, firing trigger,
- trigger executes, and examines on_hand quantity, if sufficient, it
inserts into table ORDER, firing trigger, etc..
Your application code should have already done the Insert when the trigger runs... If there are sufficient items in inventory you simply need to let the transaction be committed, you do not need to perform the insert again.
If, otoh, there are not sufficient items in inventory, then you need to rollback the transaction in the trigger (as well as any other operations initiated in the trigger.
here is kinda the way it ought to be written:
DECLARE
v_quantity_diff number;
v_onhand_quantity number;
BEGIN
-- TRIGGR ON THIS...
--INSERT INTO ORDER
--( FK_ORDER_NO, FK_PROD_ID, QUANITY , COMPLETE_STATUS)
--VALUES
--( :NEW.FK_ORDER_NO, :NEW.FK_PROD_ID, :NEW.QUANITY , :NEW.COMPLETE_STATUS);
SELECT INVENTORY_ONHAND INTO v_onhand_quantity
FROM INVENTORY
WHERE :NEW.fk_prod_id = INVENTORY.FK_PROD_ID;
IF( (:NEW.QUANTITY > v_onhand_quantity)
THEN Begin
Rollback Transaction
raise_application_error (-20001,'ERROR: QUANTITY ' || :NEW.QUANTITY
|| ' EXCEEDS INVENTORY ONHAND [' || TO_CHAR(v_onhand_quantity) || ']' );
End
END IF;
END;