dbTalk Databases Forums  

declaration & subblocks

comp.database.oracle comp.database.oracle


Discuss declaration & subblocks in the comp.database.oracle forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
vertigo
 
Posts: n/a

Default declaration & subblocks - 12-21-2004 , 11:17 AM






Hello

i have such code in PL/SQL:

.....
Declare
x number;
v number;
begin
Declare
x number;
z number;
begin
....

Does this code thru error in oracle 8,9 and 10 ?
This code will thru error because i can not declare z in internal block
if i had not declared it in external block ??


Thanx
Michal




Reply With Quote
  #2  
Old   
Hilarion
 
Posts: n/a

Default Re: declaration & subblocks - 12-21-2004 , 11:57 AM






I'm not sure if I understand your problems (you may try to explain it in Polish).

Example:

DECLARE
x NUMBER(38,0) := 1;
v NUMBER(38,0) := 2;
BEGIN
-- point one
dbms_output.put_line( 'outer x: ' || NVL( TO_CHAR( x ), 'NULL' ) );
dbms_output.put_line( 'outer v: ' || NVL( TO_CHAR( v ), 'NULL' ) );
DECLARE
x NUMBER(38,0);
z NUMBER(38,0) := 4;
BEGIN
-- point two
x := 3;
dbms_output.put_line( 'inner x: ' || NVL( TO_CHAR( x ), 'NULL' ) );
dbms_output.put_line( 'outer v: ' || NVL( TO_CHAR( v ), 'NULL' ) );
dbms_output.put_line( 'inner z: ' || NVL( TO_CHAR( z ), 'NULL' ) );
END;
-- point one
dbms_output.put_line( 'outer x: ' || NVL( TO_CHAR( x ), 'NULL' ) );
dbms_output.put_line( 'outer v: ' || NVL( TO_CHAR( v ), 'NULL' ) );
END;

The code above works OK with no errors and shows some details.
You can use variable "x" declared in outer declaration in point one and three
(it's hidden in point two by a variable with same name) and "v" in point one,
two and three. Variables declared in inner declaration: "x" (different variable
than in point one and three) and "z" can be used in point two.
You can't use "z" in point one or three cause it's not declared in this context.

Hilarion



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.