Jericho
Jericho

Reputation: 10953

PLS-00103: Encountered the symbol when expecting one of the following:

It seems ok but am getting exception please correct me.

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;

Exception :

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

Upvotes: 10

Views: 236431

Answers (3)

Du-Lacoste
Du-Lacoste

Reputation: 12787

The IF statement has these forms in PL/SQL:

IF THEN
IF THEN ELSE
IF THEN ELSIF

You have used elseif which in terms of PL/SQL is wrong. That need to be replaced with ELSIF.

So your code should appear like this.

    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; 

Upvotes: 5

user4497532
user4497532

Reputation: 1

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;

Upvotes: -7

OldProgrammer
OldProgrammer

Reputation: 12169

The keyword for Oracle PL/SQL is "ELSIF" ( no extra "E"), not ELSEIF (yes, confusing and stupid)

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;

Upvotes: 24

Related Questions