我試圖用IF.. ELSE
條件和語句來更新庫存的單位,但是當試圖運行它,我得到一個錯誤:下面的if/else在PL SQL循環
PLS-00103: Encountered the symbol "LOOP" when expecting one of the following:
if
代碼,我它運行在一個循環吐出所有的數據,直到用完:
DECLARE
--Declare cursor
CURSOR part_cur
IS
SELECT PARTNUMBER, PARTDESC, ITEMCLASS, UNITSONHAND, UNITSONHAND
FROM PART
ORDER BY UPPER(PARTNUMBER);
--Declare variables
v_PartNumber PART.PARTNUMBER%TYPE;
v_PartDesc PART.PARTDESC%TYPE;
v_ItemClass PART.ITEMCLASS%TYPE;
v_UnitsOnHand PART.UNITSONHAND%TYPE;
v_nUnitsOnHand PART.UNITSONHAND%TYPE;
BEGIN
OPEN part_cur;
LOOP
--Initialise variables
FETCH part_cur INTO v_PartNumber, v_PartDesc, v_ItemClass, v_UnitsOnHand, v_nUnitsOnHand;
EXIT WHEN part_cur%NOTFOUND;
--Perform Calculations
IF ITEMCLASS = 'AO' AND UNITSONHAND <20 THEN v_nUnitsOnHand := UNITSONHAND + 5;
ELSE IF ITEMCLASS = 'AO' AND UNITSONHAND <100 THEN v_nUnitsOnHand := UNITSONHAND + 10;
ELSE IF ITEMCLASS = 'AO' AND UNITSONHAND >=100 THEN v_nUnitsOnHand := UNITSONHAND + 25;
END IF;
--Format for output
--Output results
DBMS_OUTPUT.PUT_LINE('Part ' || UPPER(v_PartNumber) || ' - ' || INITCAP(v_PartDesc) || ' of item class ' || UPPER(v_ItemClass) || ' had a total of ' || v_UnitsOnHand || ' units on hand,
and now has ' || v_nUnitsOnHand || ' units on hand after the database was updated.
');
END LOOP;
CLOSE part_cur;
END;
任何幫助或指針將不勝感激,謝謝。用於訪問這些字段
record_var.v_PartNumber, etc
:
哦歡呼聲謝謝,我不知道有多深我的'ELSE .. IF'陳述正在進行中。 – user3521826
@ user3521826:不客氣! – ruakh