1.

Scope of Variables in PL/SQL?

Answer»

Variable Scope defines that if you DECLARE a variable within an inner bloc, it is not accessible for the outer. On the contrary, if a variable is declared in outer BLOCK, then it is accessible in the ENTIRE program whether its outer, inner, NESTED inner blocks.

The following are the scope of variables in PL/SQL:

Local variables

  • Declaration: Variables declared in an inner block
  • Accessible: Not accessible to outer blocks

Global variables

  • Declaration: Variables declared in the outermost block
  • Accessible: Accessible to outer blocks, inner block, nested inner block.

Let us now see an example to learn the role of local and global variables in scope of variables in PL/SQL:

DECLARE   -- Global variables     a number := 5;   BEGIN     dbms_output.put_line('Outer Variable a = ' || a);   DECLARE        -- Local variables      a number := 10;     BEGIN        dbms_output.put_line('Inner Variable a = ' || a);   END;   END; /

The output:

Outer Variable a = 5 Inner Variable a = 10


Discussion

No Comment Found