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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1775063/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 02:16:39  来源:igfitidea点击:

PL/SQL PLS-00103 on adding two variables

oracleplsql

提问by n a

i'm new to pl/sql and trying to print even numbers up till 100 using the following code:

我是 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;

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. \

PL/SQL 中没有 % 运算符;改用 mod(i,x) 函数。无论如何,您不需要 n 变量。sum:=sum+i 会做。sum 可能是保留字,请改用 s。\

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

同样的问题 :(

回答by Erich Kitzmueller

There is no % operator in PL/SQL; use the mod(i,x)function instead. Anyway, you don't need the n variable. sum:=sum+iwill do. But: sumis a PL/SQL keyword, use s instead.

PL/SQL 中没有 % 运算符;改用该mod(i,x)函数。无论如何,您不需要 n 变量。sum:=sum+i会做。但是:sum是 PL/SQL关键字,请改用 s。

回答by Asaithambi R

Declare
i number;
sum1  number:=0; 
x number:=2;
n number;
Begin
for i in 1..100 loop
if(i mod x =0)then
n:=i;  
sum1:=sum1+n;
end if;
end loop;
dbms_output.put_line(sum1);
end;
/

Reason :

原因 :

The "sum" is one of the aggregate function ,so we can't use this as variable name.

“sum”是聚合函数之一,因此我们不能将其用作变量名。