Home > Back-end >  PL/SQL - Nested if else if syntax
PL/SQL - Nested if else if syntax

Time:09-20

I'm developing a trigger in PL/SQL.

It has this building structure:

if a = 1 then
    if b = 1 then
        (some code here);
    else if b=2 then
        (some code here);
    else if b=3 then
        (some code here);
    else b=4
        (some code here);
    end if;
else if a=2 then
    if b=1 then
        (some code here);
    else if b=2 then
        (some code here);
    else if b=3 then
        (some code here);
    else b=4
        (some code here);
    end if;
else
    if b=1 then
        (some code here);
    else if b=2 then
        (some code here);
    else if b=3 then
        (some code here);
    else b=4
        (some code here);
    end if;
end if;

However, it seems like the last else statement(a=3) is not well defined, cause the compiler says to me that expects a " ( "

Can i have a help in here? Thank you all

CodePudding user response:

That's because you probably meant to say ELSIF, not ELSE IF (not only at the last place you mentioned, but everywhere).

Something like this:

if a = 1 then
    if b = 1 then
        (some code here);
    elsif b=2 then
        (some code here);
    elsif b=3 then
        (some code here);
    elsif b=4
        (some code here);
    end if;
elsif a=2 then
    if b=1 then ...
  • Related