using Collection variable??? [message #265363] |
Thu, 06 September 2007 03:17  |
thisisnatesh
Messages: 92 Registered: March 2007
|
Member |
|
|
Hi all
Given below is an anonymous block.
declare
type name_rec is record
(first_name varchar2(20), last_name varchar2(20));
type vrec is varray(20) of name_rec;
vrec1 vrec;
begin
null;
end;
Now i want to store values (or) use the collection
type of variable vrec1. how do i do it?
please help me in this regard..
Thanks in advance
Natesh
|
|
|
|
|
|
|
Re: using Collection variable??? [message #267008 is a reply to message #265420] |
Wed, 12 September 2007 04:28   |
sarans
Messages: 30 Registered: November 2006 Location: UK
|
Member |
|
|
Michel
I am going to implement this collection, but the only difference is, which I dont know the size of the varray:-
type vrec is varray(20) of name_rec;
How to populate data within this collection type not restricting only to 20, its dynamic...
Please let me know, how to do it...
Cheers,
Saran.
|
|
|
|
Re: using Collection variable??? [message #267152 is a reply to message #267015] |
Wed, 12 September 2007 10:39   |
sarans
Messages: 30 Registered: November 2006 Location: UK
|
Member |
|
|
Michel
Thanks for the reply, and yes I have implemented the Table type and its working fine...
Now I want to populate only unique values, to be used at later point, is there any collection methods which I can use it and how?? or do I need to use the IF condition to check whether it exists already, if not exists then add it into the Table etc.
Please let me know...
Cheers,
Saran.
|
|
|
|
Re: using Collection variable??? [message #267165 is a reply to message #267158] |
Wed, 12 September 2007 11:19   |
sarans
Messages: 30 Registered: November 2006 Location: UK
|
Member |
|
|
Michel
Thanks for the reply.
Apologies for not letting you know my requirement in the first place, I have to use 2 values, can I do it in the same way??? I am using 2 variables within the table i.e. value varchar2 and id number, see below:-
DECLARE
TYPE Name_rec IS RECORD(VALUE VARCHAR2(34),
Id NUMBER);
TYPE vrec IS TABLE OF NAME_REC INDEX BY BINARY_INTEGER ;
vrec1 VREC;
BEGIN
FOR i IN 1.. 10 LOOP
-- "how to check here??"
-- I want to check both values for the existance...
vrec1(i).VALUE := 'test'||i;
vrec1(i).Id := i;
END LOOP;
END;
please let me know
Cheers,
Saran.
[Updated on: Wed, 12 September 2007 11:29] Report message to a moderator
|
|
|
Re: using Collection variable??? [message #267170 is a reply to message #267165] |
Wed, 12 September 2007 11:29  |
 |
Michel Cadot
Messages: 68737 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Why not? I used your first example with first_name and last_name.
You can use ID to index your table of "VALUE" (myvar(ID):=VALUE).
Regards
Michel
|
|
|