Oracle PL/SQL: VARRAY (Collection) manual filling and reading for processing

With Oracle and PL/SQL you can use the COLLECTION features.
Simply fill in data into a VARRAY and also read it out.

See follwing simple PL/SQL example here:

declare
type r_rec is record(
cont_id number
,macc_id number
);
type t_v is varray(100000) of r_rec; –mail_idx%rowtype;
t_tab t_v := t_v();

procedure ext(i_cont_id in number, i_macc_id in number)
is
l_new number;
begin
–dbms_output.put_line(‘t_tab.last :’ ||t_tab.last);
l_new := nvl(t_tab.last,0)+1;
t_tab.extend;
t_tab(l_new).cont_id := i_cont_id + l_new;
t_tab(l_new).macc_id := i_macc_id + l_new;
end;
begin
dbms_output.put_line(‘———————‘);

— fill in varray, for example with only two rows
ext(i_cont_id=>44444, i_macc_id=>33333);
ext(i_cont_id=>55555, i_macc_id=>66666);

— varray processing
for i in 1..t_tab.count
loop
dbms_output.put_line(t_tab(i).cont_id);
end loop;
end;

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top