Oracle Modified field type method Summary ____oracle

Source: Internet
Author: User
There is a table named TB with the field segment named name and data type nchar (20).

1, assuming that the field data is empty, no matter what type of field to change, you can directly execute:
ALTER TABLE TB Modify (name Nvarchar2 (20));

2, assuming that the field has data, then change to NVARCHAR2 (20) can be directly executed:
ALTER TABLE TB Modify (name Nvarchar2 (20));

3, assuming that the field has data, then change to VARCHAR2 (40) when the execution will pop up: "ORA-01439: To change the data type, the column to be modified must be empty", then use the following method to solve this problem :

/* Modify the original field name, name 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);

/* Update, delete the original field name_tmp*/
ALTER TABLE TB drop column name_tmp;

Summarize:
1, when the field does not have data or to modify the new type and the original type compatible, you can directly modify modification.
2, when the field has data and to modify the new type and the original type is incompatible, to indirectly create a new field to transfer.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.