I am creating a stored procedure to bulk collect the data from one table (table 1) to another table (table 2) using limit clause .
For example if I am loading 80000 records with the limit clause of 1000 how many times the select statement in the sys refcursor gets executed? Is it going to execute once or for each limit's iteration (80000/1000) = 80 times?
Please could someone provide more details on the processing .
code skeleton snippet
create or replace procedure <procedure_name> as
<curosor name> SYS_REFCURSOR;
< collection_name > ;
begin
open <cursor_name> for <select statment>;
loop
fetch <cursor_name> into < collection_name > limit 1000;
exit when <cursor_name>%not_found;
forall i in 1..<collection_name>.count
insert statement into to table 2 values <i>
end loop;
The database will execute the cursor once. But it will fetch from it
( # rows / limit ) + 1times.You can verify this by tracing the session and formatting the trace file:
This will generate a trace file on the database server. You can find the location with this query:
Use TKPROF to format the file and you'll see something like this:
Execute = 1, Fetch = 101