PLS-00103:遇到以下其中一项时遇到符号:

时间:2013-12-13 20:01:17

标签: sql oracle plsql syntax-error

似乎没问题,但是我得到了例外,请纠正我。

declare
    var_number number;

begin
    var_number := 10;

    if var_number > 100 then
        dbms_output.put_line(var_number||' is greater than 100');
    elseif var_number < 100 then
        dbms_output.put_line(var_number||' is less than 100');
    else
        dbms_output.put_line(var_number||' is equal to 100');
    end if;

end;

例外:

ORA-06550: line 8, column 8:
PLS-00103: Encountered the symbol "VAR_NUMBER" when expecting one of the following:
    := . ( @ % ;
ORA-06550: line 13, column 4:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
    if

3 个答案:

答案 0 :(得分:13)

Oracle PL / SQL的关键字是&#34; ELSIF&#34; (没有额外的&#34; E&#34;),而不是ELSEIF(是的,令人困惑和愚蠢)

declare
    var_number number;
begin
    var_number := 10;
    if var_number > 100 then
       dbms_output.put_line(var_number||' is greater than 100');
    elsif var_number < 100 then
       dbms_output.put_line(var_number||' is less than 100');
    else
       dbms_output.put_line(var_number||' is equal to 100');
    end if;
end;

答案 1 :(得分:1)

IF语句在PL/SQL中包含以下形式:

IF THEN
IF THEN ELSE
IF THEN ELSIF

您使用了elseif,这在PL / SQL方面是错误的。这需要替换为ELSIF

所以你的代码应该是这样的。

    declare
        var_number number;
    begin
        var_number := 10;
        if var_number > 100 then
           dbms_output.put_line(var_number ||' is greater than 100');
--elseif should be replaced with elsif
        elsif var_number < 100 then
           dbms_output.put_line(var_number ||' is less than 100');
        else
           dbms_output.put_line(var_number ||' is equal to 100');
        end if;
    end; 

答案 2 :(得分:-4)

begin
    var_number := 10;

    if var_number > 100 then
        dbms_output.put_line(var_number||' is greater than 100');
    else if var_number < 100 then
        dbms_output.put_line(var_number||' is less than 100');
    else
        dbms_output.put_line(var_number||' is equal to 100');
    end if;
end if;