Oracle CONTROL STRUCTURE
PL/SQL IF/THEN/ELSE Statement The IF/THEN statement checks a Boolean value or expression and if true, executes the statements in the THEN clause.  If the condition is false, the statements in the THEN clause are skipped and execution jumps to the END IF, and the expression that is checked must return a true or false. It can be a simple Boolean variable or a compound  expression joined with AND/OR clauses, and the expression can even be a PL/SQL function that returns a Boolean value.  • IF...THEN • IF...THEN...ELSE • IF...THEN...ELSIF...ENDIF • IF…THEN…ELSIF…THEN…ELSE…END IF •
IF THEN statement • IF THEN...END IF statement is a single-level  conditional statement which executes a sequence of statements based on a given condition.  • Syntax: IF condition THEN executable statements END IF; • Condition Expression evaluates to TRUE or FALSE If TRUE commands execute
Demonstration
5 PL/SQL Comparison Operators
IF THEN ELSE statement • The IF-THEN-ELSE statement is next level of extension  of above the IF-THEN statement, as it provides the  ability to give direction for FALSE or NULL also. • Syntax:  IF condition THEN executable statements 1 ELSE executable statements 2 END IF;
Demonstration
IF THEN ELSIF ENDIF statement    • For multiple possible outcomes of a condition, we use the IF THEN ELSIF ENDIF statement    • Syntax:   IF condition1 THEN sequence_of_statements1 ELSIF condition2 THEN sequence_of_statements2 ELSE sequence_of_statements3 END IF;
Demonstration
Nested IF statement • When using an ELSIF construct, it is not necessary to specify what action should be taken if none of the conditions evaluate to TRUE. In other words, an ELSE clause is not required in the ELSIF construct.
Oracle pl/sql control statments

Oracle pl/sql control statments

  • 1.
  • 2.
    PL/SQL IF/THEN/ELSE Statement TheIF/THEN statement checks a Boolean value or expression and if true, executes the statements in the THEN clause.  If the condition is false, the statements in the THEN clause are skipped and execution jumps to the END IF, and the expression that is checked must return a true or false. It can be a simple Boolean variable or a compound  expression joined with AND/OR clauses, and the expression can even be a PL/SQL function that returns a Boolean value.  • IF...THEN • IF...THEN...ELSE • IF...THEN...ELSIF...ENDIF • IF…THEN…ELSIF…THEN…ELSE…END IF •
  • 3.
    IF THEN statement •IF THEN...END IF statement is a single-level  conditional statement which executes a sequence of statements based on a given condition.  • Syntax: IF condition THEN executable statements END IF; • Condition Expression evaluates to TRUE or FALSE If TRUE commands execute
  • 4.
  • 5.
  • 6.
    IF THEN ELSEstatement • The IF-THEN-ELSE statement is next level of extension  of above the IF-THEN statement, as it provides the  ability to give direction for FALSE or NULL also. • Syntax:  IF condition THEN executable statements 1 ELSE executable statements 2 END IF;
  • 7.
  • 8.
    IF THEN ELSIFENDIF statement    • For multiple possible outcomes of a condition, we use the IF THEN ELSIF ENDIF statement    • Syntax:   IF condition1 THEN sequence_of_statements1 ELSIF condition2 THEN sequence_of_statements2 ELSE sequence_of_statements3 END IF;
  • 9.
  • 10.
    Nested IF statement •When using an ELSIF construct, it is not necessary to specify what action should be taken if none of the conditions evaluate to TRUE. In other words, an ELSE clause is not required in the ELSIF construct.