Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ELSIF V/S ELSE IF IN ORACLE

what is difference between those two.

elsif

else if

while both are executing fine with no errors.

like image 518
Nisar Avatar asked Apr 09 '14 18:04

Nisar


People also ask

What is Elsif Oracle?

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.

How many Elsif clauses can an if statement have?

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...

How do I write if else condition in Oracle?

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...}

Which of the following is optional while using if/then Elsif statement?

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.


1 Answers

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.

like image 181
Justin Cave Avatar answered Nov 04 '22 10:11

Justin Cave