SQL Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21st 22 23 24 25 |
|
There is a table named TB, field segment named Name, data type nchar ( -).
1. Assuming that the field data is empty, you can do it directly, regardless of the field type you are changing to: Alter TableTBModify(name Nvarchar2 ( -));
2. If the field has data, change to NVARCHAR2 ( -) can be executed directly: Alter TableTBModify(name Nvarchar2 ( -));
3. If the field has data, change to VARCHAR2 ( +) will pop up when executed: "Ora-01439: To change the data type, the column you want to modify must be empty, and the following method is used to resolve the problem:
Alter TableTBRename columnname toname_tmp;
Alter TableTBAddnamevarchar2( +);
UpdateTBSetname=Trim(NAME_TMP);
Alter TableTBDrop columnname_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 Modify field Type method summary