修改数据库字段类型,但是由于数据表已经存在数据,无法修改;
显示错误:ORA-01439: column to be modified must be empty to change datatype
alter table USERS add tmp_col NUMBER(1);-- 添加临时列 update USERS set tmp_col = CUSTOMER_MARITAL_STATUS ; --将目标字段中数据加入到临时列中 update USERS set CUSTOMER_MARITAL_STATUS = null; --将目标字段数据清空 alter table USERS modify ( CUSTOMER_MARITAL_STATUS NUMBER(1)); --更改目标字段类型 update USERS set CUSTOMER_MARITAL_STATUS = tmp_col; --将临时列数据加回到目标字段中 alter table USERS drop column tmp_col; --清除临时列 SELECT DISTINCT CUSTOMER_MARITAL_STATUS FROM USERS; SELECT DISTINCT tmp_col FROM USERS;