create or replace TYPE csv_rec IS OBJECT (client_code varchar2(500),
debtor_code varchar2(500));
--
create or replace TYPE csv_table IS TABLE OF csv_rec;
--
PROCEDURE Create_Detail
(xClientCode IN NUMBER
,xStatus IN OUT VARCHAR2
,xWebCursor IN OUT SYS_REFCURSOR
) IS
--
l_client_code NUMBER;
l_array csv_table;
--
CURSOR c1 IS
SELECT t1.field1,
t2.field2
FROM table1 t1,
table2 t2
WHERE t1.client_code = l_client_code
AND t1.client_code = t2.client_code;
--
c_rec c1%ROWTYPE;
--
BEGIN
--
l_client_code := xClientCode;
--
l_array := csv_table();
--
FOR c_rec IN c1
--
LOOP
--
l_array.extend;
l_array := csv_table(csv_rec(c_rec.field1,c_rec.field2));
--
END LOOP;
--
OPEN xWebCursor FOR
SELECT * FROM TABLE(l_array);
--
xStatus := 'TRUE';
--
EXCEPTION
WHEN OTHERS THEN
xStatus := 'FALSE';
END Create_Detail;
I am having trouble that the above code will always populate the array with the final row in the cursor. I don't know how to get the 'extend' to work, or move to 'next' row in the array. It will not allow me to use l_array(index) at all so I am stumped? Can anyone help?
Try using bulk collect into instead of loop,
Note:- In case you are dealing with huge data set try suing limit with bulk collect into.
--Test
If we want to do the same with loop then we need to declare another type and use multiset union to append the result (at least I know this way)
--Test