簡體   English   中英

在ORACLE中將6000000條記錄從一個表插入到另一個表的最佳方法是什么?

[英]What is the best way to insert 6000000 records from one table to another table in ORACLE?

大家好,我需要將6000000行從TMP_DATA復制到DATA,什么是最好的方法?

我正在考慮將INSERT INTO DATA SELECT * FROM TMP_DATA 但是我認為插入會花費很多時間。

你有什么建議?

親切的問候,

有兩種方法可以做到這一點:

如果您想提高速度,請使用並行和無日志記錄(在新表上):

-警告:這種方法速度很快,但會占用大量CPU資源,因此讓

-DBA知道。 另外,在表末尾建立索引。

create table DATA SELECT parallel 4 nologging as
select * from TMP_DATA;

如果您使用的是現有表,則可能會降低插入性能的一件事就是使用索引。 您可以臨時禁用索引,以加快插入速度。

要進一步了解Anders的答案和mathguy的評論,請執行以下操作:

alter table data nologging;
alter session enable parallel dml;
-- disable any triggers on `data` and temporarily drop any indexes

insert /*+ append */ * into data 
select /*+ parallel (4) */ * from tmp_data
--sample (10)  -- if tmp_data has 60 million rows: 10 means 10%
-- where rownum < 6000001 
-- pick one of the two prior clauses if tmp_table has > 6 million rows

插入完成后:

alter table data nologging;  
-- enable triggers and recreate indexes

並讓dba進行備份,因為如果加載后出現任何問題, data表將無法恢復。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM