PL/SQL PLS-00103 关于添加两个变量
我是 pl/sql 新手,尝试使用以下代码打印 100 以内的偶数:
Declare
i number;
sum number:=0;
x number:=2;
n number;
Begin
for i in 1..100 loop
if (i%x=0) then
n:=i;
sum:=sum+n;
end if;
end loop;
dbms_output.put_line(sum);
end;
我收到此错误
ERROR at line 10:
ORA-06550: line 10, column 12:
PLS-00103: Encountered the symbol "+" when expecting one of the following:
(
ORA-06550: line 13, column 26:
PLS-00103: Encountered the symbol ")" when expecting one of the following:
(
帮助? :(
PL/SQL 中没有 % 运算符;请使用 mod(i,x) 函数。无论如何,您不需要 n 变量。sum:=sum+i 就可以了。sum 可能是保留字,使用 s 代替。 \
现在:
Declare
i number;
sum number:=0;
Begin
for i in 1..100 loop
if (mod(i,2)=0) then
sum:=sum+i;
end if;
end loop;
dbms_output.put_line(sum);
end;
同样的问题:(
i'm new to pl/sql and trying to print even numbers up till 100 using the following code:
Declare
i number;
sum number:=0;
x number:=2;
n number;
Begin
for i in 1..100 loop
if (i%x=0) then
n:=i;
sum:=sum+n;
end if;
end loop;
dbms_output.put_line(sum);
end;
i get this error
ERROR at line 10:
ORA-06550: line 10, column 12:
PLS-00103: Encountered the symbol "+" when expecting one of the following:
(
ORA-06550: line 13, column 26:
PLS-00103: Encountered the symbol ")" when expecting one of the following:
(
Help? :(
There is no % operator in PL/SQL; use the mod(i,x) function instead. Anyway, you don't need the n variable. sum:=sum+i will do. sum might be a reserved word, use s instead.
\
Now:
Declare
i number;
sum number:=0;
Begin
for i in 1..100 loop
if (mod(i,2)=0) then
sum:=sum+i;
end if;
end loop;
dbms_output.put_line(sum);
end;
sameproblem :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PL/SQL中没有%运算符;请改用
mod(i,x)
函数。无论如何,你不需要 n 变量。sum:=sum+i
就可以了。但是:sum
是 PL/SQL 关键字,使用 s 代替。There is no % operator in PL/SQL; use the
mod(i,x)
function instead. Anyway, you don't need the n variable.sum:=sum+i
will do. But:sum
is a PL/SQL keyword, use s instead.原因:
“sum”是聚合函数之一,所以我们不能使用它作为变量名。
Reason :
The "sum" is one of the aggregate function ,so we can't use this as variable name.