Home » SQL & PL/SQL » SQL & PL/SQL » need the values of a variable inside a for loop (Oracle 10g version)
need the values of a variable inside a for loop [message #299744] Wed, 13 February 2008 01:43 Go to next message
swapnajojo
Messages: 40
Registered: June 2007
Location: India
Member
Hi Friends ,

Please help me with this issue

I have created a procedure .


CREATE or replace procedure p AS
2 x1 varchar2(5):='a';
3 x2 varchar2(5):='b';
4 c varchar2(20);
5 v varchar2(10);
6 v2 varchar2(10);
7 rows int;
8 begin
9 for i in 1..2
10 loop
11 v:='x'||i;
12 dbms_output.put_line(v);
13 c:=c||v||',';
14 dbms_output.put_line(c);
15 end loop;
16* end;
SQL> /

Procedure created.

SQL> exec p
x1
x1,
x2
x1,x2,

PL/SQL procedure successfully completed.

Instead I need output like a,b

We need to use loop because we may have many variable like x1 to x100

Thanks In Advance
Binu
Re: need the values of a variable inside a for loop [message #299747 is a reply to message #299744] Wed, 13 February 2008 01:57 Go to previous messageGo to next message
Michel Cadot
Messages: 64111
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
This has already been told to you:
Read and follow OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code.
Use the "Preview Message" button to verify.

As you are a newbie post in newbie forum.

Use 100 lines, just copy and paste, it is easy.

Regards
Michel
Re: need the values of a variable inside a for loop [message #299761 is a reply to message #299747] Wed, 13 February 2008 02:25 Go to previous messageGo to next message
swapnajojo
Messages: 40
Registered: June 2007
Location: India
Member
Please help me
Re: need the values of a variable inside a for loop [message #299763 is a reply to message #299761] Wed, 13 February 2008 02:31 Go to previous messageGo to next message
MarcS
Messages: 312
Registered: March 2007
Location: Antwerp
Senior Member
swapnajojo wrote on Wed, 13 February 2008 09:25
Please help me


We would like to help, but it's not completely clear to me what your problem actually is.

(and I advice you also to not ignore Michaels post Wink )
Re: need the values of a variable inside a for loop [message #299764 is a reply to message #299761] Wed, 13 February 2008 02:31 Go to previous messageGo to next message
vamsi kasina
Messages: 2107
Registered: October 2003
Location: Riyadh, Saudi Arabia
Senior Member
Please read the guidelines and follow them.
After that seek for help.

By
Vamsi
Re: need the values of a variable inside a for loop [message #299767 is a reply to message #299761] Wed, 13 February 2008 02:46 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
swapnajojo wrote on Wed, 13 February 2008 09:25
Please help me

Reread Michel's post. He advised you how to do it.
Re: need the values of a variable inside a for loop [message #299769 is a reply to message #299744] Wed, 13 February 2008 02:48 Go to previous message
flyboy
Messages: 1832
Registered: November 2006
Senior Member
> We need to use loop because we may have many variable like x1 to x100

It is not possible to get variable content when "dynamically" creating its name, as it will not be visible in that scope.
Use one collection (TABLE OF or VARRAY) instead of many variables. It will be easy to loop it.
Otherwise you have to access the variables one by one.
Previous Topic: Stored Procedure Output Advice?
Next Topic: Query giving wrong result on time
Goto Forum:
  


Current Time: Mon Dec 05 14:49:57 CST 2016

Total time taken to generate the page: 0.11433 seconds