"Oracle Batch Update" compares the method of updating another large table in bulk with one large table

Source: Internet
Author: User

The "problem" now has two tens other structures of the same data in different data tables T_sms_phoneno (destination table), T_sms_phoneno2 (source table), updating the data of the destination table based on the source table data.

"Analysis" based on experience, the Update method generally has the following types:

1, direct update.

Update T_sms_phoneno T Set t.name= (select NAME from T_sms_phoneno2 where Phoneno=t.phoneno)

2, the use of sub-article update. Updated by record ID.

Open cur is select phoneno,name from T_sms_phoneno;

Loop

Fetch cur in v_pn,v_name;

Update T_sms_phoneno T set t.name=v_name where V_pn=t.phoneno;

Exit when cur% NotFound;

End Loop

3, the use of batch update. The data is updated in batches by the table partitioning field or other fields in turn.

Open cur is select region from T_sms_phoneno Group by region;

Loop

Fetch cur in v_region;

Update T_sms_phoneno T set t.name= (select NAME from T_sms_phoneno2 where Phoneno=t.phoneno) where t.region=v_region;

Exit when cur% NotFound;

End Loop

4, virtual a table, the only association after the update.

Update (select T.name,t2.name name2 from T_sms_phoneno T,t_sms_phoneno2 T2 where T.phoneno=t2.phoneno) set name=name2;

5. Create a new table and update it.

CREATE TABLE Temp_sms_phoneno as SELECT * from T_sms_phoneno T,t_sms_phoneno2 T2 where T.phoneno=t2.phoneno;

Generate a new table, and then rename the table to T_sms_phoneno

Conclusion

1, for large table update if the use of Direct UPDATE statement, it will directly produce a large number of rollback, and the time is very long, there is a phenomenon of suspended animation.

2, 1 hours.

3, 30 minutes.

4, 2 minutes.

5, 30 seconds, the INSERT statement will be very fast because it does not produce a redo,undo action.

If there is a unique associated field, then the fourth method is updated quickly, if there is no unique associated field, it needs to be updated in batches, or create a new table.

"Oracle Batch Update" compares the method of updating another large table in bulk with one large table

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.