ELSIF V/S ELSE IF IN ORACLE
ELSIF does not need a matching END IF. If the condition for the 1st IF is not satisfied, then the ELSIF condition is checked.
ELSE IF will need a matching END IF, because a new IF block is started.
References:
PL/SQL Control Statements on Oracle® Database PL/SQL Language Reference
An IF
statement in PL/SQL is structured as
IF <<some condition>>
THEN
<<do something>>
ELSIF <<another condition>>
THEN
<<do something else>>
ELSE
<<do a third thing>>
END IF;
where both the ELSIF
and the ELSE
are optional. If you are seeing an ELSE IF
, that indicates that someone is creating a nested IF
statement (with a nested END IF
) in an ELSE
block. That is
IF <<some condition>>
THEN
<<do something>>
ELSE
IF <<another condition>>
THEN
<<do something else>>
END IF;
END IF;
You can, if you so desire, nest PL/SQL blocks as deeply as you'd like. Generally, though, your code will be cleaner if you don't nest things more than necessary. Unless there is a compelling reason here to create a nested IF
statement, you're much more likely to produce readable code using a single IF
statement with one or more ELSIF
blocks (or, even better, a CASE
). Plus, that way you're not trying to count up all the END IF
statements you need to close all the nested IF
statements.