Reputation: 1603
I am writing a simple arithmetic pl/sql code block to calculate the average of a column of numbers (I know this can be done using the AVG in select statement).
However, I am encountering problems in the arithmetic. I simply can't think of what can be wrong.
Please point out the mistake. It is giving me the following error.
Encountered the symbol "+" when expecting one of the following: (
DECLARE
VMENU MENU%ROWTYPE;
CURSOR SELECTPRICE IS
SELECT * FROM MENU;
AVERAGE NUMBER(7,2):=0;
SUM NUMBER(7,2):=0;
COUNT NUMBER(2):=0;
BEGIN
OPEN SELECTPRICE;
LOOP
FETCH SELECTPRICE INTO VMENU;
EXIT WHEN SELECTPRICE%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(VMENU.TYPE||' '||VMENU.ITEM||' '||VMENU.PRICE);
SUM:=SUM+VMENU.PRICE;
COUNT:=COUNT+1;
END LOOP;
AVERAGE:=SUM/COUNT;
DBMS_OUTPUT.PUT_LINE(AVERAGE);
CLOSE SELECTPRICE;
END;
Upvotes: 0
Views: 465
Reputation: 36892
Change the variable names SUM
and COUNT
to something other than a reserved word. For example, the code will run if the variables are changed to V_SUM
and V_COUNT
.
Upvotes: 3