问题是这样的,有一个员工表(Employee),现在要用控制语句来统计工资(salary)的总和,不用sum()函数,我写一个这样的PL/SQL块,但是运行报错:1 DECLARE
2 TYPE array_salary IS VARRAY(50) OF Employee.salary%TYPE;
3 temp_salary arrary_salary;
4 CURSOR sum_salary IS SELECT salary FROM Employee;
5 sum Employee.salary%TYPE;
6 i INT := 1;
7 count INT := 0;
8 BEGIN
9 SELECT COUNT(*) INTO count FROM Employee;
10 IF NOT sum_salary%ISOPEN THEN
11 OPEN sum_salary;
12 FETCH sum_salary BULK COLLECT INTO temp_salary;
13 WHILE i <= count LOOP
14 TO_NUMBER(sum) := TO_NUMBER(sum) + TO_NUMBER(temp_salary(i));
15 i := i + 1;
16 END LOOP;
17 CLOSE sum_salary;
18 dbms_output.put_line(sum);
19 END;
/
/**********************************报一下一下错误××××××/
ORA-06550: line 15, column 14:
PLS-00103: Encountered the symbol "+" when expecting one of the following:(The symbol "(" was substituted for "+" to continue.
ORA-06550: line 15, column 30:
PLS-00103: Encountered the symbol ";" when expecting one of the following:   . ( ) * % & - + / at mod remainder rem <an exponent (**)> ||
The symbol ")" was substituted for ";" to continue.
ORA-06550: line 18, column 26:
PLS-00103: Encountered the symbol ")" when expecting one of the following:   (
哪位能够帮帮忙啊

解决方案 »

  1.   

    sum是什么类型的?直接指定成NUMBER
    然后14行
    sum:=sum+ TO_NUMBER(temp_salary(i)); 
      

  2.   

    按二楼的方法做了但是还是不行
    还是一样的错误,salary是NUMBER类型的。
    一楼的大哥能说的清楚点吗
    呵呵小弟没明白什么意思呵呵
      

  3.   

    2楼的修改是必须的另外sum的初始化0的代码呢?
      

  4.   

    知道是什么原因,因为sum是oracle中的关键字,不能用来作为变量呵呵
    改个名字就可以了比如s。谢谢各位了!