How Oracle modifies the data type when the column is not empty

Source: Internet
Author: User
Tags commit

– New temporary columns

ALTER TABLE TableName Add filedname_temp number (2);

– Empty the value of the temporary column

Update Zyt set id_temp=null; -----#alter Table TableName modify filedname null;

– Move the value of the field you want to update to a temporary column and empty the column

Update tablename set filedname_temp=filedname,filedname=null;

Commit

– Modify the column's data type to VARCHAR2

ALTER TABLE TableName Modify Filedname varchar2 (20);

– Move the temporary column value back to the column and empty the temporary column

Update tablename set filedname=filedname_temp,filedname_temp=null;

Commit

– Delete temporary columns

ALTER TABLE tablename drop column filedname_temp;

– cannot be empty for this column

ALTER TABLE TableName modify filedname NOT null;

– Perform query tests

SELECT * FROM TableName;

In this way, you don't have to change the name of the column. Table migration will not occur, but there is a disadvantage is that the table to update two times, and when the amount of data, resulting in the undo and redo also more, the premise is to stop the operation, if not down, you can also use the online redefinition way to do.

Note: Please change the TableName and filedname for your own actual value.

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.