Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

insert a large amount of records into a table

992831Feb 26 2013 — edited Feb 26 2013
I was trying to find a fast way to optimize a script that insert a large amount of records into a table. The initial script was like

insert into table_xxxx
select a.camp1, a.camp2, a.camp3 a.camp4, b.camp1, b.camp2, b.camp3
from table_a a, table_b b
where a.camp0 = b.camp0

The commit sentence was at the end of the insert script; so i came up with this solution

Declare
TYPE cur_CURSOR IS REF CURSOR ;
TYPE Tab_Hist IS TABLE OF table_xxxx%ROWTYPE INDEX BY BINARY_INTEGER;
g_tHist Tab_Hist;

CURSOR c_Base IS
select a.camp1, a.camp2, a.camp3 a.camp4, b.camp1, b.camp2, b.camp3
from table_a a, table_b b
where a.camp0 = b.camp0;

BEGIN
OPEN c_base;
LOOP
FETCH c_base BULK COLLECT INTO g_tHist LIMIT 1000;
EXIT WHEN g_tHist.COUNT = 0;
BEGIN
FORALL i IN g_tHist.FIRST .. g_tHist.COUNT SAVE EXCEPTIONS
INSERT INTO prov_cobr_dud VALUES g_tHist(i);
COMMIT;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
END;
g_tHist.DELETE;
EXIT WHEN c_base%NOTFOUND;
END LOOP;
CLOSE c_base;
----
commit;
----

END;

If anyone could tell me another way to do the same thing i'll apreciate it a lot; i'm keen on learn more efficient ways to optimize scripts.

PD: The initial insert was inserting the table with 120,000 records (more or less)
This post has been answered by Paul Horth on Feb 26 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 26 2013
Added on Feb 26 2013
8 comments
505 views