Steps for modifying the field type in Oracle

Source: Internet
Author: User

The following articles mainly describe the actual operation scheme for modifying the field type in Oracle. We all know that the actual application of modifying the field type in Oracle is more common, it is advantageous to understand the actual operation steps. The following describes the specific content of the article.

To modify the Data Type of a field as required by the business, change it to number (5 ).

C. Use the following statement if there is no data

 
 
  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; 

Modifying the field type in Oracle may change the column name, and row migration may occur when the field order is increased, which may 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 is an introduction to the method for modifying the field type in Oracle. I hope you will find some gains.

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.