plsql - pl sql 中 while 循环出错

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

这里有什么问题吗?

这是错误消息:

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: 
(

最佳答案

尝试不使用变量名称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;
/

似乎有效

关于plsql - pl sql 中 while 循环出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34463322/

相关文章:

plsql - 在 mod pl/sql 中设置 http 响应头

sql - PL/SQL 使用表变量作为查询表

带有 DBMS_ASSERT 的 Oracle SQL 注入(inject) block

python - Ipywidgets 生态系统中用于中断循环的停止按钮

sql - 当PL SQL匿名 block 完成时,为什么没有输出?

sql - PL/SQL 写一个更新列的程序?

java - While(matcher.find()) - 错误 - 不起作用

c - 尝试在循环中使用 scanf 扫描值。需要辅助输入来打印第一个输入

php - 带有 mysql_fetch_array 的嵌套 While 循环给出空白结果

c - 在 C 中时(使用 log Not)