我是新來的PL/SQL,並使用下面的代碼試圖打印偶數截至100:PL/SQL PLS-00103上增加兩個變量
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 +我會這樣做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;
sameproblem :(