ID USERNAME
---------- --------------------
1 tom1
2 tom2
3 tom3
SQL> select * from t2;
ID USERNAME
---------- --------------------
1 jack1
2 jack2
即:SQL> select * from t1;
ID USERNAME
---------- --------------------
1 jack1
2 jack2
3 tom3
方法一:
merget into t1 using t2 on (t1.id=t2.id)
when matched then
update set t1.username=t2.username;
方法二
update t1 set t1.username=(select t2.username from t2 where t2.id=t1.id) where exists(select 1 from t2 where t2.id=t1.id);
误区:
update t1 set t1.username=(select t2.username from t2 where t2.id=t1.id);
SQL> select * from t1;
ID USERNAME
---------- --------------------
1 jack1
2 jack2
3