How Does Oracle modify the data type when the column is not empty?

Source: Internet
Author: User

-Add a temporary Column

Alter table tablename add filedname_temp number (2 );

-Leave the value of the temporary column empty.

Update zyt set id_temp = null; ----- # alter table tablename modify filedname null;

-The field value to be updated is moved to the temporary column, and this column is left empty.

Update tablename set filedname_temp = filedname, filedname = null; commit;

-Change the Data Type of a column to varchar2.

Alter table tablename modify filedname varchar2 (20 );

-Move the temporary column value to the column again, and leave the temporary column empty.

Update tablename set filedname = filedname_temp, filedname_temp = null; commit;

-Delete temporary Columns

Alter table tablename drop column filedname_temp;

-This column cannot be blank.

Alter table tablename modify filedname not null;

-Run the query test.

Select * from tablename;

In this way, you do not need to change the column name or migrate the table. However, the disadvantage is that the table must be updated twice. If the data volume is large, more undo and redo operations are generated on the premise that the operation is stopped. If the operation is not stopped, you can use the online redefinition method.

Note: replace tablename and filedname as your actual values.

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.