且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在oracle pl SQL中找到sum

更新时间:2022-05-29 22:02:25

问题是总和是保留字(参见 Summation - Wikipedia [ ^ ])。



尝试更改变量名称。例如 mysum

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;
/