ORA-01440:要减小精度或标度,则要修改的列必须为空

  • Post author:
  • Post category:其他


我们要减小精度或标度, 则要修改的列必须为空,而我们本来表中是存在数据的,那么直接alter修改字段是会报错的;

解决方法:

1.先将字段重命名

alter table table01 rename column money to money_bak;

2.在新增一列 money,并改成要修改的精度

alter table table01 add(money number(12,2));

3.将money_bak的值赋值给money列

update table01 set money = trim(money_bak);

4.删除money_bak列

alter table table01 drop column money_bak;

这样我们就将money字段的精度修改成number(12,2);

使用四条sql就可以修改字段的精度:

alter table table01 rename column money to money_bak;

alter table table01 add(money NUMBER(12,2));

update table01 set money = trim(money_bak);

alter table table01 drop column money_bak;

题外话:当然如果工作中数据很重要的话,建议对修改的表先进行备份,然后在执行上面的sql进行修改;



版权声明:本文为Laoluyoudu原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。