Two ways of Oracle parallel update (merge/update inline view)

Source: Internet
Author: User

forOraclethe two-table Joint update scenario (withA,Btwo tables, toa.id=b.idAssociation, according toBrecord updates in the tableAthe corresponding fields in the table), typicallyUpdateinline views andMergetwo ways, the following examples are:

To create a use case table:

CREATE table Test1 (ID number (), name VARCHAR2 (20));

CREATE TABLE Test2 (ID number (), name VARCHAR2 (20));

Test data:

Begin

INSERT into test1 values (1, ' A ');

INSERT into test1 values (2, ' B ');

INSERT into test2 values (1, ' C ');

INSERT into test2 values (2, ' D ');

End

Merge Way:

Merge into Test1 using Test2

On (test1.id = test2.id)

When matched then update

Set test1.name = Nvl2 (test1.name,test2.name,test1.name);

Merge methods are the most concise and efficient way to use this approach when big data volumes are updated.

Update Inline view mode:

This method must be used intest2.idThere is a primary key on it (well understood here and must guarantee that everytest1.idcorresponds totest2only one record, iftest2there are several corresponding records, how to updatetest1? ), which is generally more expensive thanMergeWay slightly higher.

ALTER TABLE TEST2 add constraint Pk_test2 primary key (ID); --/*+ BYPASS_UJVC */

Update (select/*+ bypass_ujvc */a.id aid,a.name aname,b.id bid,b.name bname from test1 a,test2 b where a.id=b.id) t

Set aname = Nvl2 (aname,bname,aname);

Use parallelism to speed up large volumes of data updates:

Merge/*+parallel (test1,4) */into Test1 using Test2

On (test1.id = test2.id)

When matched then update

Set test1.name = Nvl2 (test1.name,test2.name,test1.name);

Two ways of Oracle parallel update (merge/update inline view)

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.