Identifiers defined in the declaration of the child block are only in scope and visible within the child block itself. : Variable Scope « PL SQL « Oracle PL / SQL






Identifiers defined in the declaration of the child block are only in scope and visible within the child block itself.

  
SQL>
SQL>
SQL> declare
  2    l_parent_number number;
  3  begin
  4    -- l_parent_number is visible and in scope
  5    l_parent_number := 1;
  6
  7    declare
  8      l_child_number number := 2;
  9    begin
 10      -- l_child_number is visible and in scope
 11      dbms_output.put_line('parent + child = ' ||
 12                            to_char(l_parent_number + l_child_number));
 13    end;
 14
 15    -- l_child_number is now not visible nor in scope:
 16    l_child_number := 2;
 17  end;
 18  /
  l_child_number := 2;
  *
ERROR at line 16:
ORA-06550: line 16, column 3:
PLS-00201: identifier 'L_CHILD_NUMBER' must be declared
ORA-06550: line 16, column 3:
PL/SQL: Statement ignored


SQL>
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.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
5.This type is local to this block
6.Reference Type in another block as well
7.variable scope with nested block
8.Override your scope access to containing blocks by reusing an identifier in a nested block