2011-06-24 93 views
1

可能重複:
What is the fastest way to insert data into an Oracle table?從一個表副本25萬條記錄到另一個表在Oracle

表擁有25萬條記錄。我需要在此表中添加新列數據類型爲date,並將數據複製到同一表下舊列的新列中,但舊列具有時間戳數據類型。我正在做下面的步驟,你能否讓我知道我能做到的其他任何方式。當我運行follwing查詢它運行6或7小時,然後我必須殺死它。數據庫是oracle。

alter table ofr_ft rename to ofr_ft_bkup; 

CREATE TABLE ofr_ft ( 
all old columns, 
     age  DATE NOT NULL, 
CONSTRAINT ofr_ft_pk 
PRIMARY KEY (ofr_ft_id) 
); 

INSERT INTO ofr_ft 
      (old coumns, 
      age) 
    (values from old columns, 
      cast(date_last_chng as date) 
     FROM ofr_ft_bkup); 

COMMIT; 
+0

Oracle是否有相當於SQL Server集成服務 - 也就是說,一個允許創建導入數據包的程序? –

回答

0

通常情況下,先禁用密鑰,執行插入,然後啓用密鑰通常會更快。

此外,研究不在交易中的速度是否更快。

4

爲什麼你想創建一個新表?

alter table mytable add (newcolumn date); 
update mytable set newcolumn = oldcolumn; 
alter table mytable drop (oldcolumn); 

如果更新不工作,因爲回滾段太小了,這樣的事情應該做的伎倆:

alter table mytable add (newcolumn date); 
begin 
    loop 
    update mytable set newcolumn = oldcolumn 
     where oldcolumn is not null 
     and newcolumn is null 
     and rownum<=10000; 
    exit when sql%rowcount=0; 
    commit; 
    end loop; 
end; 
/
alter table mytable drop (oldcolumn); 
相關問題