I have two tables ITEMS_MASTER this table include my (ITEM_CODE, ITEM_NAME,ITEM_QTY ,…) And the other table is called STK_TRANS_DETAILS I insert the items(ITEM_CODE,QTY,PRICE,ITEM_NAME,..) in it based on the DOC_NUMBER and THE TK_CODE . I want to write trigger ON THE TABLE STK_TRANS_DETAILS(this trigger is after insert or update or delete) to update qty column(more than one item in item_master table based on the number of items inserted in the stk_trans_details table based on the doc_number) in items_master table with a value equal to item_qty column in item_master table + qty column in stk_trans_detail table if TK_CODE in stk_trans_detail table =1 or 3 and the ITEM_CODE in the two table are the same value and the DOC_NUMBER in STK_TRANS_DETAILS equal to the page item P113_DOC_NUMBER. and if tk_code = 2 value equal to item_qty column in item_master table – qty column in stk_trans_detail table when the ITEM_CODE in the two table are the same value and the DOC_NUMBER in STK_TRANS_DETAILS equal to the page item P113_DOC_NUMBER.
i have tried to do that using trigger but i have got an error .
this is one of my trial
after
insert or update on "STK_TRANS_DETAILS"
for each row
DECLARE
V_TK NUMBER;
V_QTY NUMBER;
BEGIN
SELECT TK_CODE INTO V_TK FROM STK_TRANS_DETAILS WHERE DOC_NUMBER = :OLD.DOC_NUMBER AND ITEM_CODE = :OLD.ITEM_CODE;
SELECT QTY INTO V_QTY FROM STK_TRANS_DETAILS WHERE DOC_NUMBER = :OLD.DOC_NUMBER AND ITEM_CODE = :OLD.ITEM_CODE;
IF V_TK = 1 THEN
UPDATE ITEMS_MASTER SET ITEM_QTY = ITEM_QTY + V_QTY WHERE ITEM_CODE = :OLD.ITEM_CODE;
ELSIF V_TK = 2 THEN
UPDATE ITEMS_MASTER SET ITEM_QTY = ITEM_QTY - V_QTY WHERE ITEM_CODE = :OLD.ITEM_CODE;
ELSE
UPDATE ITEMS_MASTER SET ITEM_QTY = ITEM_QTY + V_QTY WHERE ITEM_CODE = :OLD.ITEM_CODE;
END IF;
END; ```
i have tried to do that using process but got an error .
how can i do that?