There is a table named TB, field segment named Name, data type nchar (20).
1. Assuming that the field data is empty, you can do it directly, regardless of the field type you are changing to:
ALTER TABLE TB Modify (name Nvarchar2 (20));
2, if the field has data, then to NVARCHAR2 (20) can be directly executed:
ALTER TABLE TB Modify (name Nvarchar2 (20));
3, if the field has data, then to VARCHAR2 (40) execution will pop up: "ORA-01439: To change the data type, the column to be modified must be empty", the following method to solve the problem :
/* Modify the original field name name to name_tmp*/
ALTER TABLE TB Rename column name to Name_tmp;
/* Add a field with the same name as the original field name*/
ALTER TABLE TB Add name VARCHAR2 (40);
/* Update the original field NAME_TMP data to the added field name*/
Update TB set Name=trim (NAME_TMP);
/* Finish updating, delete the original field name_tmp*/
ALTER TABLE TB drop column name_tmp;
Summarize:
1, when the field has no data, or to modify the new type and the original type is compatible, you can directly modify modification.
2. When the field has data and is incompatible with the new type and the original type to be modified, create a new field to transfer indirectly.
Oracle modifying field types