Nesting Functions and Procedures : Nested Block « PL SQL Statements « Oracle PL/SQL Tutorial






SQL> SET ECHO ON
SQL> SET SERVEROUTPUT ON
SQL>
SQL> DECLARE
  2  temp  NUMBER;
  3
  4    FUNCTION iifn(boolean_expression IN BOOLEAN,
  5                true_number IN NUMBER,
  6                false_number IN NUMBER)
  7    RETURN NUMBER IS
  8    BEGIN
  9      IF boolean_expression THEN
 10        RETURN true_number;
 11      ELSIF NOT boolean_expression THEN
 12        RETURN false_number;
 13      ELSE
 14        --nulls propagate, i.e. null input yields null output.
 15        RETURN NULL;
 16      END IF;
 17    END;
 18  BEGIN
 19    DBMS_OUTPUT.PUT_LINE(iifn(2 > 1,1,0));
 20    DBMS_OUTPUT.PUT_LINE(iifn(2 > 3,1,0));
 21
 22    temp := iifn(null,1,0);
 23    IF temp IS NULL THEN
 24      DBMS_OUTPUT.PUT_LINE('NULL');
 25    ELSE
 26      DBMS_OUTPUT.PUT_LINE(temp);
 27    END IF;
 28  END;
 29  /
1
0
NULL

PL/SQL procedure successfully completed.

SQL>
SQL>








22.12.Nested Block
22.12.1.Nested Blocks
22.12.2.A nested block which declares and prints a variable of the same name
22.12.3.This is an example of nested anonymous blocks
22.12.4.Nesting Functions and Procedures
22.12.5.Call function in PL/SQL