Skip to Main Content
  • Questions
  • Bulk insert and update of large amounts of data

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question.

Asked: November 16, 2015 - 8:20 pm UTC

Last updated: November 17, 2015 - 3:56 am UTC

Version: Oracle 11g

Viewed 10K+ times! This question is

You Asked

What is the best method for inserting a couple million rows into an existing table that has the fastest load time?

and Connor said...

a direct mode insert is probably the quickest, but it has implications - in particular, your table is locked whilst the insert takes place.

But on an unindexed table, you can expect this to be very quick

SQL> create table T ( x int, y date, z varchar2(100));

Table created.

SQL>
SQL> set timing on
SQL>
SQL> insert /*+ APPEND */ into T
  2  select rownum, sysdate, 'some string'
  3  from dual
  4  connect by level <= 2000000;

2000000 rows created.

Elapsed: 00:00:04.79


If the table cannot be locked...then the answer depends on what facilities you have available, eg

1) if the table is partitioned, you could load a separate table and 'exchange' the partition in

2) you could create a second copy of the table with the new data as well, use triggers to capture the deltas on the true table, and then swap the names over with a small outage

But even with standard mode insert, 2 million rows isnt a huge deal - although in all cases, the number of indexes you have on the table is a critical factor.

Hope this helps.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Blue inserting into an existing table

A reader, November 17, 2015 - 2:12 am UTC

Extremely helpful since I'm not a PLSQL expert and the response was given so quickly. This will certainly help us to move forward with our project and it provided multiple alternatives as well as the pro's and cons of each.
Connor McDonald
November 17, 2015 - 3:56 am UTC

Thanks for the feedback.

I should have added, you can achieve the same in PLSQL in terms of efficiency. There is

1) bulk binding, which is fast conventional mode insert
2) bulk binding with the APPEND_VALUES hint, which makes it a direct mode insert (faster but locking implications).

Hope this helps

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library