oracle中只更新兩張表對應數據的方法
前提:有表table1和table2.表結構都是id,name。
問題:當table1的id和table2的id相同時更新table1的name爲table2的name
解決方案:update table1 set name = (select name from table2 where table1.id = table2.id) where exists (select 1 from table2 where table1.id = table2.id)
解釋:where條件是防止table1中存在的id而table2中不存在的id所對應的數據被清空
注:以上語句僅在oracle11g中測試通過