PL/SQL PLS-00103添加两个变量

n a*_*n a 2 oracle plsql

我是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;
Run Code Online (Sandbox Code Playgroud)

我收到这个错误

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:
( 
Run Code Online (Sandbox Code Playgroud)

救命?:(

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;
Run Code Online (Sandbox Code Playgroud)

同样的问题 :(

Eri*_*ler 5

PL/SQL中没有%运算符; 请改用此mod(i,x)功能.无论如何,你不需要n变量.sum:=sum+i会做.但是:sum是PL/SQL 关键字,而是使用s.