Override your scope access to containing blocks by reusing an identifier in a nested block : Variable Scope « PL SQL « Oracle PL / SQL






Override your scope access to containing blocks by reusing an identifier in a nested block

  

SQL>
SQL> DECLARE
  2    current_block VARCHAR2(10) := 'Outer';
  3    outer_block   VARCHAR2(10) := 'Outer';
  4  BEGIN
  5    dbms_output.put_line('[current_block]['||current_block||']');
  6    DECLARE
  7
  8      current_block VARCHAR2(10) := 'Inner';
  9    BEGIN
 10      dbms_output.put_line('[current_block]['||current_block||']');
 11      dbms_output.put_line('[outer_block]['||outer_block||']');
 12    END;
 13    dbms_output.put_line('[current_block]['||current_block||']');
 14  END;
 15  /
[current_block][Outer]
[current_block][Inner]
[outer_block][Outer]
[current_block][Outer]

PL/SQL procedure successfully completed.

SQL>

   
    
  








Related examples in the same category

1.Variable scope in variable 'declare' block
2.Illustrates the scope of various identifiers
3.Variable scope in a PL/SQL
4.Identifiers defined in the declaration of the child block are only in scope and visible within the child block itself.
5.if you try to reference a variable before you declare it because PL/SQL requires an identifier be declared before we use it in our code
6.This type is local to this block
7.Reference Type in another block as well
8.variable scope with nested block