一开始建表时候没注意精度问题,后来需求中要求保留三位小数(之前两位),在有数据情况下不能直接使用alter
解决思路:先在该表中新增一个临时字段,将之前是需要修改的字段的值赋给临时字段,然后删除需要修改的字段后重新新增三位小数的字段,再将临时字段中的值赋给它,删除临时字段
实例:
表名-LOGIS_MATERIAL_WAREHOUSING
需要修改的字段-WAREHOUSING_NUMBER
临时字段-col1
alter table LOGIS_MATERIAL_WAREHOUSING add (col1 number(22,3));
update LOGIS_MATERIAL_WAREHOUSING set col1 = round(WAREHOUSING_NUMBER,3);
alter table LOGIS_MATERIAL_WAREHOUSING drop column WAREHOUSING_NUMBER;
alter table LOGIS_MATERIAL_WAREHOUSING add (WAREHOUSING_NUMBER number(22,3));
update LOGIS_MATERIAL_WAREHOUSING set WAREHOUSING_NUMBER = col1;
alter table LOGIS_MATERIAL_WAREHOUSING drop column col1;