DECLARE
-- create record type
TYPE rec IS RECORD (a NUMBER, b NUMBER);
-- create associative array of record type
TYPE test_rec is TABLE OF rec index by binary_integer ;
-- declare collection variable , doesn't need to get initialized
v_test_rec test_rec;
-- declare cursor to get set of records
CURSOR c1 IS SELECT LEVEL a , LEVEL*10 b FROM DUAL CONNECT BY LEVEL < 5;
i number;
counter number ;
BEGIN
i := 1; -- initialize counter
counter := 1; -- initialize counter
-- Open cursor explicitly, fetch all data into collection variable in one go and explicitly close the cursor .
FOR c2 IN c1 LOOP
v_test_rec(i).a :=C2.a ;
v_test_rec(i).b :=C2.b ;
i := i+1;
END LOOP;
-- loop through nested table data for display purpose
FOR counter IN v_test_rec.first..v_test_rec.last loop
dbms_output.put_line('Field a ' || v_test_rec(counter).a || ' Field b ' ||v_test_rec(counter).b );
END LOOP;
END;
Comments
Post a Comment