I am developing a stored procedure with a cursor of bulk collect. I initially developed a static cursor with bulk collect as below:
procedure p_get_x ( p_x in NUMBER )
is
l_var1 is number;
cursor c_x is
select
col1, col2
from tbl1
where col1 = l_var1
;
t_x c_x%rowtype;
TYPE tab_x IS TABLE OF t_x%TYPE;
tb_x tab_x;
BEGIN
open c_x;
fetch c_x bulk collect into tb_x ;
close c_x
;
for idx in 1 .. tb_x.count
loop
insert into tbl2
(
col1,
col2
)
values (
tb_x(idx).col1,
tb_x(idx).col2
);
end loop;
commit;
end if;
end p_get_x;
The requirement is to create a generic procedure. Based on input - p_x, the procedure have to execute different cursor definition, but only 1 cursor in an execution. The cursor table name will be different and each table will have some common column names and few specific column names. example :- table a - col1, col2 ,col3 table b - col1, col3, col4
How to create a dynamic cursor wilt bulk collect as on average there would be 5 Million rows in that table?
References I tried: Dynamic Variable in Cursor in Oracle stored procedure dynamic table name in cursor
Thanks