I need help with my sql script.
Inventory is a table which contains orderunit, location, siteid and itemnum. This update aims to change all "orderunit = NULL" by the same item (itemnum) in such a way :
%_TAB => %_TD
and
%_TD => %_ACM
I want the same result with cursors :
UPDATE INVENTORY A
SET A.orderunit = (SELECT B.orderunit
FROM INVENTORY B
WHERE B.location = A.siteid || '_TD'
AND B.itemnum = A.itemnum)
WHERE A.location = A.siteid || '_TAB'
AND A.orderunit IS NULL;
UPDATE INVENTORY A
SET A.orderunit = (SELECT B.orderunit
FROM INVENTORY B
WHERE B.location = A.siteid || '_ACM'
AND B.itemnum = A.itemnum)
WHERE A.location = A.siteid || '_TD'
AND A.orderunit IS NULL;
I tried to make this and it seems not to work.
DECLARE
inv_itemnum INVENTORY.itemnum%TYPE
inv_location INVENTORY.location%TYPE
inv_siteid INVENTORY.siteid%TYPE
inv_orderunit INVENTORY.orderunit%TYPE
CURSOR c_inventory_tab IS
SELECT orderunit FROM INVENTORY WHERE location = siteid || '_TAB' AND orderunit IS NULL
FOR UPDATE;
CURSOR c_inventory_td IS
SELECT orderunit FROM INVENTORY WHERE location = siteid || '_TD' AND orderunit IS NULL
FOR UPDATE;
CURSOR c_inventory_tabB
SELECT orderunit FROM INVENTORY WHERE location = siteid || '_TD' AND itemnum = itemnum;
CURSOR c_inventory_tdB
SELECT orderunit FROM INVENTORY WHERE location = siteid || '_ACM' AND itemnum = itemnum;
BEGIN
FOR i IN c_inventory_tab
LOOP
UPDATE INVENTORY
SET orderunit = c_inventory_tabB;
END LOOP;
END;
Thanks for your help