2011-06-24 56 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); 
相关问题