The problem is that
sum
is a reserved word (see
Summation - Wikipedia[
^]).
Try to change the variable name. For example
mysum
:
DECLARE
type namearray IS VARRAY(5) OF VARCHAR2(10);
type grade IS VARRAY(5) OF INTEGER;
names namearray;
marks grade;
total integer;
mysum integer := 0;
BEGIN
names := namearray('Kavita', 'Pritam', 'Ayan', 'Rishav', 'Aziz');
marks := grade(98, 97, 78, 87, 92);
total := names.count;
dbms_output.put_line('Total '|| total || ' Students');
FOR i in 1 .. total LOOP
mysum := mysum + marks(i);
dbms_output.put_line(marks(i));
END LOOP;
dbms_output.put_line(mysum / total);
END;
/