Question

I have a table 'A' having 40 columns. I need to copy the data from 20 specific columns from 'A' , to another table 'B' having those 20 columns. There will be around 3 - 10 million records. What will be the most efficient way to do this in PLSQL.

Was it helpful?

Solution

"daily table B will be truncated and new data will be inserted into it from A."

Okay, so the most efficient way to do this is not to do it. Use a materialized view instead; a materialized view log on table A will allow you to capture incremental changes and apply them daily, or at any other window you like. Find out more.

Compared to that approach using handrolled PL/SQL - or even pure SQL - is laughably inefficient.

OTHER TIPS

Do you need to do any sort of conversion on the data or is it just copying data straight from one table to another?

The easiest way to do this is, although you would have to create the indexes separately.

create table B as (select A.c1, A.c2, A.c3..... from A);

If table x already existed, you could just do a

insert into B select A.c1, A.c2.... from A

To speed this up, you would want to drop all the indexes on table x until the insert was done.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top