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

标签 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;

我收到此错误

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/

相关文章:

java - 如何在java中做连接池?

java - "see"Java标准库可以离线吗

sql - 甲骨文 SQL : Most efficient way to calculate Z-score of grouped data

sql - Oracle "ORA-01008: not all variables bound"错误带参数

oracle - 在许多包中使用的带有声明但没有定义的类型

oracle - 从表中选择DISTINCT CLOB_COLUMN;

oracle - 是否可以从另一个调用 oracle 对象类型构造函数?

java - AJAX/JavaScript 搜索性能优于 Java/Oracle

java - 无法连接到JReport中的数据库

oracle - Oracle Apex 集合中的 ApEx 表单