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