Home » SQL & PL/SQL » SQL & PL/SQL » PL/SQL
PL/SQL [message #226662] Mon, 26 March 2007 02:24 Go to next message
kr_arvind
Messages: 85
Registered: April 2006
Location: Delhi
Member
Hi,

How can fatch the main block variable in subblock without change the variable name.

Is it possible if possible then please help me

declare
x number :=10;
y number;
begin
declare
x number:=5;
begin
y:=x+x;
dbms_output.put_line(y);
end;
end;

OUTPUT
y=15


Thanks
Arvind
Re: PL/SQL [message #226664 is a reply to message #226662] Mon, 26 March 2007 02:30 Go to previous messageGo to next message
dhananjay
Messages: 635
Registered: March 2002
Location: Mumbai
Senior Member
hi,

one of the way to do the same.
<<outer>>
declare
x number :=10;
y number;
begin
declare
x number:=5;
begin
y:=outer.x+x;
dbms_output.put_line(y);
end;
end;




regards,
Re: PL/SQL [message #226667 is a reply to message #226664] Mon, 26 March 2007 02:36 Go to previous messageGo to next message
Frank
Messages: 7901
Registered: March 2000
Senior Member
A far far better way would be to use different names.
Re: PL/SQL [message #226679 is a reply to message #226667] Mon, 26 March 2007 03:16 Go to previous messageGo to next message
Michel Cadot
Messages: 68718
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

Indeed!
Re: PL/SQL [message #226687 is a reply to message #226664] Mon, 26 March 2007 03:47 Go to previous messageGo to next message
kr_arvind
Messages: 85
Registered: April 2006
Location: Delhi
Member
Thanks its working fine
Re: PL/SQL [message #226688 is a reply to message #226664] Mon, 26 March 2007 03:48 Go to previous messageGo to next message
kr_arvind
Messages: 85
Registered: April 2006
Location: Delhi
Member
Thanks
Re: PL/SQL [message #226791 is a reply to message #226667] Mon, 26 March 2007 09:28 Go to previous messageGo to next message
Ericle
Messages: 44
Registered: April 2006
Location: United States of America ...
Member

Frank wrote on Mon, 26 March 2007 03:36
A far far better way would be to use different names.


Seems obvious, doesn't it? I can't think of any reason why the variable names would need to be the same. Making them the same only makes it confusing.
Re: PL/SQL [message #226974 is a reply to message #226791] Tue, 27 March 2007 00:43 Go to previous message
Frank
Messages: 7901
Registered: March 2000
Senior Member
Yep, but I want to bet you the OP used the outer. syntax to 'solve' his problem...
Previous Topic: SQL Server
Next Topic: Concatenation
Goto Forum:
  


Current Time: Thu Dec 05 07:44:00 CST 2024