Oracle modifies the column type. oracle modifies the column type.

Source: Internet
Author: User

Oracle modifies the column type. oracle modifies the column type.
1. If the field data is empty, you can directly execute the following command regardless of the field type:
Alter table tb modify (name nvarchar2 (20 ));

2. If the field has data, you can change it to nvarchar2 (20) and execute it directly:
Alter table tb modify (name nvarchar2 (20 ));

3. If the field has data, it will pop up when it is changed to varchar2 (40) Execution: "ORA-01439: to change the data type, the column to be modified must be blank ", the following method is used to solve the problem:

/* Change the original field name to name_tmp */
Alter table tb rename column name to name_tmp;

/* Add a field name with the same name as the original field name */
Alter table tb add name varchar2 (40 );

/* Update the original field name_tmp to the added field name */
Update tb set name = trim (name_tmp );

/* After the update, delete the original field name_tmp */
Alter table tb drop column name_tmp;

Summary:
1. When the field does not have data or the new type to be modified is compatible with the original type, you can directly modify it by modify.
2. When a field has data and is incompatible with the original type, it is required to create a new field indirectly for transfer.

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.