有个大表test,大约2亿笔资料,有个字段A,为number类型,现在需要修改其为varchar2(50):
1. 添加临时列 data_temp
alter table test add data_temp varchar2(50);
2. 并行将字段A的资料写到data_temp上
alter session enable parallel dml
update/*+parallel(t 10)*/ test t set data_temp=a;
3.将列A置空
update/*+parallel(t 10)*/ test t set a=null;
4.修改列A的属性
alter table test modify a varchar2(50);
5.将data_temp的值再写回来
update/*+parallel(t 10)*/ test t set a=data_temp;
6.将data_temp置为unused
alter table test set unused(data_temp);
7.将data_temp列删掉
alter table test drop unused columns;
通过实验这样做效果还是不错的。。。。