Partial commit inserts in Oracle to prevent redo from consuming too much to commit transactions in batches: The following are three different pl/sql bodies:
1, write a simple pl/sql block to simulate the case-by-line submission, pay attention to observe the execution time. Our goal is to insert all the data from the T_ref table into T.
Sec@ora10g> Set Timing on
Sec@ora10g> DECLARE
2 BEGIN
3 for cur in (SELECT * from T_ref) LOOP
4 INSERT into T VALUES cur;
5 COMMIT;
6 End LOOP;
7 End;
8/
Pl/sql procedure successfully completed.
elapsed:00:03:12.77
A total of 3 minutes and 12 seconds per row commit.
2, again to simulate the situation of batch submission.
sec@ora10g> truncate TABLE t;
Table truncated.
Sec@ora10g> DECLARE
2 V_count number;
3 BEGIN
4 for cur in (SELECT * from T_ref) LOOP
5 INSERT into T VALUES cur;
6 V_count: = V_count + 1;
7 IF v_count >= THEN
8 COMMIT;
9 End IF;
Ten end LOOP;
COMMIT;
End;
13/
Pl/sql procedure successfully completed.
elapsed:00:01:27.69
This time is 1 minutes 27 seconds, approximately half the time to commit the method line by row. This shows that Oracle should try to complete the work in bulk submissions.
3, finally we use Oracle more advanced method to complete the above task, experience the limit speed.
Sec@ora10g> DECLARE
2 CURSOR cur is
3 SELECT * from T_ref;
4 TYPE Rec is TABLE of t_ref%rowtype;
5 RECs Rec;
6 BEGIN
7 OPEN cur;
8 while (TRUE) LOOP
9 FETCH cur BULK COLLECT
into RECs LIMIT 100;
One forall i in 1. RECs. COUNT
INSERT into T VALUES RECs (i);
COMMIT;
The EXIT when Cur%notfound;
End LOOP;
Close cur;
The end;
18/
elapsed:00:00:09.75