This is an example of nested anonymous blocks : Nested Block « PL SQL Statements « Oracle PL/SQL Tutorial






SQL>
SQL> SET ECHO ON
SQL> SET SERVEROUTPUT ON
SQL>
SQL> DECLARE
  2    error_flag  BOOLEAN := false;
  3
  4  BEGIN
  5    DBMS_OUTPUT.PUT_LINE('We are going to count from 100 to 1000.');
  6
  7    DECLARE
  8      hundreds_counter  NUMBER(1,-2);
  9    BEGIN
 10      hundreds_counter := 100;
 11      LOOP
 12        DBMS_OUTPUT.PUT_LINE(hundreds_counter);
 13        hundreds_counter := hundreds_counter + 100;
 14        IF hundreds_counter > 1000 THEN
 15          EXIT;
 16        END IF;
 17       END LOOP;
 18    EXCEPTION
 19    WHEN OTHERS THEN
 20      error_flag := true;
 21    END;
 22
 23    IF error_flag THEN
 24      DBMS_OUTPUT.PUT_LINE('Sorry, I cannot count that high.');
 25     ELSE
 26      DBMS_OUTPUT.PUT_LINE('Done.');
 27    END IF;
 28  END;
 29  /
We are going to count from 100 to 1000.
100
200
300
400
500
600
700
800
900
Sorry, I cannot count that high.

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