Oracle modifying field types

Source: Internet
Author: User

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

Related Article

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.