Initialisation of VARRAY of RECORDs
How do I initialise a VARRAY of RECORDS using literals?
If I define the record using:
TYPE t_myrecord IS RECORD (
field1 varchar2(5),
field2 varchar2(5),
field3 varchar2(5) );
and then define the array type:
TYPE t_myarray IS VARRAY(20) OF
t_myrecord;
and then define and initialise the array using:
a_myarray t_myarray := t_myarray();
where all of the above is listed between the DECLARE and first BEGIN statements, any attempt to assign values to the array within the BEGIN block gives either a 'VARRAY not initialised error' or 'wrong number or type of parameter into t_myarray' when using syntax like:
a_myarray(1) := t_myarray('a', 'b', 'c');
Also, the following syntax complains that t_myrecord is not defined:
a_myarray := t_myarray(
t_myrecord('a', 'b', 'c'),
t_myrecord('d', 'e', 'f'),
t_myrecord('g', 'h', 'i'));
Even if I use this last syntax in the DECLARE block.
Does anyone have any working examples?
I'm using Oracle 9.2.3.0 on an AIX 5L platform.
:confused:
Maybe you have to declare another variable like a_myrecord...
DECLARE
TYPE t_myrecord IS RECORD ( field1 varchar2(5), field2 varchar2(5), field3 varchar2(5) );
TYPE t_myarray IS VARRAY(20) OF t_myrecord;
a_myrecord t_myrecord;
a_myarray t_myarray := t_myarray();
BEGIN
a_myrecord.field1 := 'a';
a_myrecord.field2 := 'b';
a_myrecord.field3 := 'c';
a_myarray.extend(19);
a_myarray(1) := a_myrecord;
a_myarray(2) := a_myrecord;
-- ...
a_myarray.extend(1); -- plus last extend of max 20
a_myarray(20) := a_myrecord;
END;
/