Tuesday, July 22, 2014

Sample BULK collect example


set serveroutput on;

declare
cursor get is
select * from all_objects
where rownum <= 100
and object_type = 'TABLE';

TYPE t_get IS TABLE OF get%ROWTYPE;
l_get t_get;

j number:=0;
begin

open get;
 loop

  FETCH get BULK COLLECT INTO l_get LIMIT 20 ;
  EXIT WHEN l_get.count = 0;
 
    for i in 1 .. l_get.count loop
     j := j+1;
     dbms_output.put_line ('table_name('||j||')    '|| l_get(i).object_name);
    end loop;
   
 end loop;
close get;

exception
  when others then
dbms_output.put_line ('error : '||sqlerrm);
end;