pl sql中while循环出错

Joh*_*bey 2 plsql while-loop

我使用while循环来计算Pl Sql中从1到10的整数.

这是代码:

set serveroutput on;
declare
i number := 0;
sum number := 0;
begin
while i <= 10 loop
sum := sum + i ;
i := i + 1;
end loop;
dbms_output.put_line ( sum );
end;
/
Run Code Online (Sandbox Code Playgroud)

这里有什么问题?

这是错误消息:

sum := sum + i ;
           *
ERROR at line 6: 
ORA-06550: line 6, column 12: 
PLS-00103: Encountered the symbol "+" when expecting one of the following: 
( 
ORA-06550: line 9, column 28: 
PLS-00103: Encountered the symbol ")" when expecting one of the following: 
(
Run Code Online (Sandbox Code Playgroud)

Ed *_*eal 5

尽量不要使用变量名sum.

set serveroutput on;
declare
i number := 0;
s number := 0;
begin
while i <= 10 loop
s := s + i ;
i := i + 1;
end loop;
dbms_output.put_line ( s );
end;
/
Run Code Online (Sandbox Code Playgroud)

似乎工作