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)