Tuesday, November 30, 2010

Oracle - Display Outer and Inner Block Values, using same variable name

<<BLOCK1>>
DECLARE
    FLAG VARCHAR2(15) := 'OUTER BLOCK';

BEGIN
   
    DBMS_OUTPUT.PUT_LINE(FLAG);
   
    BEGIN
     <<BLOCK2>>
        DECLARE
            FLAG VARCHAR2(15) := 'INNER BLOCK';
        BEGIN
           
            DBMS_OUTPUT.PUT_LINE('OUTER BLOCK: ' ||BLOCK1.FLAG);
            DBMS_OUTPUT.PUT_LINE('INNER BLOCK: ' ||BLOCK2.FLAG);
       
        END;
   
    END;

END;




OUTPUT:

OUTER BLOCK
OUTER BLOCK: OUTER BLOCK
INNER BLOCK: INNER BLOCK

No comments:

Post a Comment