SQL>
SQL> --Illustrates the scope of various identifiers.
SQL> SET SERVEROUTPUT ON
SQL>
SQL> DECLARE
2 a_name VARCHAR2(30) := 'A Name';
3
4 PROCEDURE name_print IS
5 BEGIN
6 DBMS_OUTPUT.PUT_LINE(a_name);
7 END;
8
9
10 BEGIN
11 DBMS_OUTPUT.PUT_LINE(a_name);
12
13 DECLARE
14 b_name VARCHAR2(30) := 'a Name';
15 BEGIN
16 DBMS_OUTPUT.PUT_LINE('Inside nested block');
17 DBMS_OUTPUT.PUT_LINE(a_name);
18 DBMS_OUTPUT.PUT_LINE(b_name);
19 name_print;
20 END;
21
22 DBMS_OUTPUT.PUT_LINE('Back in the main block');
23 --But we cannot compile the following line because b_name
24 --is not defined in this block.
25 --DBMS_OUTPUT.PUT_LINE(b_name);
26 name_print;
27 END;
28
29
30 /
A Name
Inside nested block
A Name
a Name
A Name
Back in the main block
A Name
PL/SQL procedure successfully completed.
SQL>