Skip to main content
← PL/SQL Topics

Language Basics

Explain identifier scope, visibility and qualified names in nested PL/SQL blocks

Identifier Scope and Qualification

ExplanationOracle Fusion / EBS · Technical · PL/SQLHigh confidenceGenerated

An inner block sees outer identifiers; a local declaration with the same name hides the outer one, which you can still reach with a block label.

How it works

An identifier is visible from its declaration to the END of the block it is declared in, including nested blocks. If an inner block declares its own variable of the same name, the inner one wins inside that block (the outer is 'hidden'). Label the outer block (<<outer>>) to qualify the hidden name as outer.v. The same qualification (procedure_name.parameter) resolves a collision between a parameter and a column name in embedded SQL.

How it works
<<outer>>
DECLARE
  v_x NUMBER := 1;
BEGIN
  DECLARE
    v_x NUMBER := 2;             -- hides outer.v_x
  BEGIN
    DBMS_OUTPUT.PUT_LINE('inner v_x  = ' || v_x);        -- 2
    DBMS_OUTPUT.PUT_LINE('outer.v_x = ' || outer.v_x);   -- 1
  END;
END;
/

Related questions

GroundingGenerated

Model-generated, grounded against the curated knowledge layer. Check specifics against your instance.

Have a follow-up, or a different question?

Continue in Ask Oracle AI