我是 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;
同样的问题:(
最佳答案
PL/SQL中没有%运算符;请改用 mod(i,x)
函数。无论如何,你不需要 n 变量。 sum:=sum+i
就可以了。但是: sum
是一个 PL/SQL keyword ,使用 s 代替。
关于oracle - PL/SQL PLS-00103 关于添加两个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1775063/