Oracle table type method for modifying

A table named tb, the segment name field name, data type nchar (20).

1, assuming that the data field is empty, then no matter how field change type, can be executed directly:
ALTER Modify Table TB (name nvarchar2 (20));

2, the data field is assumed, then the following nvarchar2 (20) can be directly executed:
ALTER TB modify Table (name NVARCHAR2 (20 is));

. 3, the data field is assumed, then the following varchar2 (40) will pop up, when executed: "ORA-01439: to change the data type, modified columns must have to be empty", then use the following method to solve this problem : /

* modify the original name for the field name * name_tmp /
the ALTER the rename column name to the Table TB name_tmp;

/ * add a name and the same name as the original * field name /
the ALTER the Add name the Table TB VARCHAR2 (40);

/ * update to the original data field name_tmp added field * name /
update TB = TRIM SET name (name_tmp);

/ * End update, delete the original field * name_tmp /
ALTER Table TB drop column name_tmp;

summary:
1, when there is no data field to be modified or new types and compatible with the type of the original, it can be modified directly modify.
2, when the data field is not compatible with the new type and to modify the original type, the new field to be an indirect transfer.

 

Reprinted: https://www.cnblogs.com/yuyuchen/p/8087432.html

Guess you like

Origin www.cnblogs.com/wuhanjackh/p/11943713.html