I have an Oracle table called Products. It has a ID column with the type of NUMBER
.
I'd like to change its type to Number(20, 0)
but it's giving me this error:
ORA-01440: column to be modified must be empty to decrease precision or scale
So I've used this script:
alter table Products add ID_TEMP NUMBER(20,0);
update Products set ID_TEMP = ID;
update Products set ID = NULL;
alter table Products modify ID NUMBER(20,0);
update Products set ID = ID_TEMP;
alter table Products drop column ID_TEMP;
But it complains that
cannot update ID to NULL
which is reasonable as it's a not nullable primary key.
How to change its datatype from Number
to Number(20, 0)
?