Login   Search
Skip Navigation Links
Home
Application Security Tips
Oracle , PL/SQL
IT Product Reviews
Project Management
Forum
Contact Us
Links & References
Avoid SQL Injection attack
Threats and Countermeasures: S.T.R.I.D.E
Input Validation
Session Management
Authentication Mechanism
Cross Site Scripting Vulnerabilities
Configuration Management
Scroll up
Scroll down
Oracle 9i - Programming basics PL/SQL
PL/SQL - Conditional Statements – IF
PL/SQL -Nested Block
LOOPS in PL/SQL
PL/SQL Records
Cursors in PL/SQL
PL/SQL Tables
PL/SQL Exceptions
PL/SQL Procedures
PL/SQL Functions
Oracle supplied packages
Packages
PL/SQL Ref Cursors
Types in Oracle PL/SQL
Varrays
Nested Table
Bfile and LOBs
Bulk Binding
Know Depandencies
PL/SQL Wrapper
Triggers
Scroll up
Scroll down
DBMS_SQL package
DBMS_DDL Package
DBMS_JOB Package
UTL_FILE Package
DBMS_METADATA Package
DBMS_PIPE Package
DBMS_SESSION Package
Scroll up
Scroll down

 

Blog

  • Imperativeness of agile methodology in software development
  • Get list of installed softwares on machines in your network
  • VMWare - Error - the vmware authorization service is not running
  • Add chart / graphs in ASP.net application / website
  • Microsoft Ramp Up

Blog

  • Review: uCertify.com: PrepKit for: 70-529 (C#)
  • Bird eye Review: uCertify.com: PrepKit for: 70-529 (C#)
Skip Navigation Links>Oracle , PL/SQL>PL/SQL -Nested Block

Nested Blocks
 
declare
 x number;
 
begin
 x := 80;
dbms_output.put_line(‘abc’);
declare
y number;
begin
y := 90;
dbms_output.put_line('Inner Block variable value ' || y);
end;
 
dbms_output.put_line('Outer Block variable value ' || x);
end;
 
Scope of variables
 
A variable declared in the outer block is accessible in the inner block. But a variable declared in the inner block is accessible only in the inner block.
 
declare
outer number;
begin
outer := 80;
declare
inner number;
begin
inner := 90;
dbms_output.put_line('Inner Block variable value ' || inner);
dbms_output.put_line('Outer block variable is accessible in the inner
   block’);

dbms_output.put_line('Outer block variable value ' || outer);  
end;
 
dbms_output.put_line('Outer Block variable value ' || outer);
dbms_output.put_line('Inner Block variable value ' || inner);
end;
/

Labels

If the variables names of the outer and inner blocks are same then labels have to be used within the inner block to avoid ambiguity.

<>
declare
x number;
begin
declare
 x  number := 100;
begin
 dbms_output.put_line('Value of the inner block x is ' || x);

     -- Giving value of x of the inner block to the outer block x
 outer_block.x := x;
end;
 x := x 500;
 
dbms_output.put_line('Value of the outer block x is ' || x);
end;
/

Discussion about PL/SQL Nested block

AuthorBody
Rahul
7/12/2009 3:51 AM
Please provide feedback about this article here.

To participate in this discussion Sign up for free membership of 24x7code.

To Signup click on Login , Use create user link & the follow the instructions.

Thank you.



Designed & Developed by Rahul Bagal