Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to modify field type in oracle
How to modify field type in oracle

Due to business needs, the data type of a certain field needs to be modified from number(5) to number(5,2). If there is no data, just use the following statement: alter table tb_test modify permile number (5,2); But if you have data, you cannot use the above method, alter table tb_test add permile_temp number(5,2) update tb_test set permile_temp=permile; alter table drop column permile; alter table test rename column permile_temp to permile; This method will cause the column names to change, and the increase in field order may cause row migration, which will have an impact on the application. The following method is a better method without changing the column names and will not cause table migration, but there is a problem with this The disadvantage is that the table needs to be updated twice. If the amount of data is large, more undo and redo will be generated. The prerequisite is that it must be shut down. If it is not shut down, you can also use online redefinition. The following is the script: alter table tb_test add permile_temp number ; Add/modify columns alter table tb_test modify PERMILE null; update tb_test set permile_temp=permile,permile=null; commit; alter table tb_test modify permile number(5,2); update tb_test set permile=permile_temp,permile_temp=null; commit; alter table tb_test drop column permile_temp; alter table tb_test modify PERMILE not null; select * from tb_test ;Editor: Xiaocao