比如一个为number型的字段,在有数据的情况下修改为varchar2如果是空列,可以直接用alter table modify(col varchar2(100))来实现,如果这一列不为空,需要怎么处理,表中的数据量上千万.

解决方案 »

  1.   

    1.先增加一列
    alter table tableName add temp varchar2;
    2.然后使用number(t)列更新temp列
    update tableName set temp=t;
    3.然后删除number列
    alter table tableName drop t;
    4.重命名temp列为t
    alter table tableName rename column temp to t
      

  2.   

    update 上千万的数据会很慢很慢的。
      

  3.   

    有数据的话可以先新增一列 
    alter table tb add newcol varchar2(100)
    alter table tb nologging--不写入日志
    update tb set newcol=oldcol --赋值
    alter table tb drop column oldcol --删除老的
    alter table tb rename column newcol to oldcol--改会老的字段名
      

  4.   


    你可以尝试做一些加快更新速度的准备,比如禁用约束和索引,禁用logging.加大日志文件大小等等
      

  5.   


    1、直接新建一张表
    CREATE TABLE test (..,col varchar2(100),..) NOLOGGING --其它栏位跟你原来表一样
    2、将原表数据插入新表
    INSERT /*+append*/ INTO test SELECT * FROM tab
    3、drop 原表
    3、rename test表名为你原来的表
    4、alter table tab logging
      

  6.   


    补充一点,如果你原表上有索引,那么在执行上面4个步骤完后,再rebuild INDEX 
      

  7.   


    在drop原表的时候就已经把索引删掉了,还怎么rebuild呢?
    有没有方法再更新表中数据的时候暂时让索引失效?
      

  8.   


    索引不能disable 可以不使用,你可以这样
    alter   table  mytest  nologging;
    alter index t_idx unusable;
    alter session set skip_unusable_indexes=true;
      

  9.   

    alter table mytest nologging;
    alter index t_idx unusable;
    alter session set skip_unusable_indexes=true;第2步和第3步的作用是啥呢,是指在这个会话周期内,索引不能使用,如果另外连接一个会话,索引一样有效,是这样么?谢谢
      

  10.   

    drop 的是原来的表,而你现在是要新的表,新表上没有你原表的index  当然要重建索引了啊
      

  11.   


    考虑了下update的redo大于insert 的最好的方法 是 重建个表 create table newtb as select * from oldtb where 1<>1
    alter table newtb modify(col varchar2(100))
    alter table newtb nologging
    --把约束都建好
    把数据采用 insert /*+ append */ into newtb select * from oldtb
    commit
    然后
    truncate table oldtb
    drop table oldtb purge--改回原表名
    rename newtb to oldtb
    建索引
    alter table oldtb nologging