oracle中修改已存在数据的列

在oracle中,如果已经存在的数据的某些列,假如要更换类型的话,有的时候是比较麻烦的, 

会出现:ORA-01439: column to be modified must be empty to change datatype


-- 修改khi_cdocument表,PRETREATMENT_NUMBER类型改为 number


alter table khi_cdocument add PRETREATMENT_NUMBER_temp VARCHAR2(50);


update khi_cdocument set PRETREATMENT_NUMBER_temp=PRETREATMENT_NUMBER,PRETREATMENT_NUMBER=null;


alter table khi_cdocument modify PRETREATMENT_NUMBER Number;


update khi_cdocument set PRETREATMENT_NUMBER=PRETREATMENT_NUMBER_temp,PRETREATMENT_NUMBER_temp=null;


alter table khi_cdocument drop column PRETREATMENT_NUMBER_temp;

你可能感兴趣的:(oracle)