Common Methods for modifying related fields in Oracle

Source: Internet
Author: User

The following articles mainly introduce several common types of Oracle field modification and the actual operation methods. Due to business needs, you need to modify the Oracle field, the data type is number (5) and changed to number (5, 2). If there is no data, use the following statement.

 
 
  1. alter table tb_test modify permile number(5,2); 

However, if there is data, you cannot use the above method,

 
 
  1. alter table tb_test add permile_temp number(5,2)  
  2. update tb_test set permilepermile_temp=permile;  
  3. alter table drop column permile;  
  4. alter table test rename column permile_temp to permile; 

This method will change the column name, and the addition of field sequence may cause row migration, which will affect the application.

The following methods are recommended:

Table migration does not occur if the column name does not change, but the disadvantage is that the table needs to be updated twice.

If the data volume is large, more undo and redo will be generated, on the premise that the downtime is required.

If the service is not stopped, you can use the online redefinition method.

The following is a script:

 
 
  1. alter table tb_test add permile_temp number;  
  2. Add/modify columns  
  3. alter table tb_test modify PERMILE null;  
  4. update tb_test set permilepermile_temp=permile,permile=null;  
  5. commit;  
  6. alter table tb_test modify permile number(5,2);  
  7. update tb_test set permile=permile_temp,permile_temp=null;  
  8. commit;  
  9. alter table tb_test drop column permile_temp;  
  10. alter table tb_test modify PERMILE not null;  
  11. select * from tb_test ; 

The above content describes how to modify the field type in Oracle. I hope it will help you in this regard.

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.