what is difference between those two.
elsif
else if
while both are executing fine with no errors.
ELSIF. Introduces a Boolean expression that is evaluated if none of the preceding conditions returned TRUE . THEN. If the expression returns TRUE , the statements after the THEN keyword are executed.
When you want to define more than two blocks of statements, use the ElseIf Statement. You can nest up to ten levels of If... Then... Else statements. If you need to create an expression with more than ten levels, you must redefine it using the ElseIf statement or the Select Case...
Syntax (IF-THEN-ELSIF-ELSE) The syntax for IF-THEN-ELSIF-ELSE in Oracle/PLSQL is: IF condition1 THEN {... statements to execute when condition1 is TRUE...}
The ELSE clause in the IF-ELSIF is the “otherwise” of the statement. If none of the conditions evaluate to TRUE, the statements in the ELSE clause are executed. But the ELSE clause is optional. You can code an IF-ELSIF that has only IF and ELSIF clauses.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With