Oracle - insert only rows with column value which doesn't exist in table

31 views Asked by At

I have two identical tables in Oracle (identical by structure) - table_temp and table_total.

I need to insert in table_total rows from table_temp based on following condition - only rows from table_temp with PLAYER_ID value which doesn't exist in table_total should be inserted in table_total.

Table_temp has 112 milions of records.

I tried many solutions but it took too long time to process so I stopped execution. This is my last try I stopped after 7 hours:

INSERT INTO table_total
SELECT * 
FROM table_temp 
WHERE table_temp.player_id NOT IN (SELECT player_id FROM table_total)

What is best/fastest solution for this? Indexing column is not acceptable solution...

1

There are 1 answers

1
MT0 On

Use a MERGE statement:

MERGE INTO table_total dst
USING table_temp src
ON (src.player_id = dst.player_id)
WHEN NOT MATCHED THEN
  INSERT (player_id, col1, col2, col3)
  VALUES (scr.player_id, src.col1, src.col2, src.col3);