2. Oracle
- update TA a set(name, remark)=(select b.name, b.remark from TB b where b.id=a.id)
- where exists(select 1 from TB b where b.id=a.id)
注意如果不添加后面的exists语句,TA关联不到的行name, remark栏位将被更新为NULL值, 如果name, remark栏位不允许为null,则报错。 这不是我们希望看到的。
- --when name, remark is not null, cause error.
- --if allow null, rows in TA not matched will be update to null.
- update TA a set(name, remark)=(select b.name, b.remark from TB b where b.id=a.id);