关联更新update

下面三条语句从最终结果上看是等效的:

(1)update t1  set c3= 'XXX'
where exists ( select 1 from  t2 where t2.id=t1.id and t2.username=t1.username);


create index t1_idx on t1(id,username);

(2) update t1 set c3= 'YYY'
where (id,username) IN (select id,username from t2  );

(3)
merge into  t1
using t2
on (t1.id =t2.id and t1.username =t2.username)
when matched  then  
    update set c3= 'ZZZ';

SQL> select * from t1;

        ID USERNAME             C3
---------- -------------------- --------------------
         1 tom1
         2 tom2
         3 tom3
         4 tom4


SQL> select * from t2;

        ID USERNAME             C3
---------- -------------------- --------------------
         2 tom2
         4 tom4
         5 tom5

请使用浏览器的分享功能分享到微信等