Oracle SQL使用經驗 && Oracle 用left join 更新數據

4520阅读 0评论2015-04-28 gangjh
分类:Oracle

 
  我這里說的,用left join update數據的是指
    有a,b兩表,將b表數據根據某個歸則關聯更新到a表.
 
Oracle.寫法1  目前用得最多的,  注意: 當b表沒有對應數據時,  a表 xxx欄位會更新為null
  update a set a.xxx = (select b.eee from b where a.bid = b.id)
Update emp
  Set(sal,comm) = (select sal,comm. From emp1 where emp.empno = emp1.empno)
 
Oracle.寫法2 用merge
  merge into a
  using b
  on (a.a=b.b)
  when matched then update set xxxxx
  when not matched then insert (xxx) values(xxx);
 
其它寫法,Oracle 不支持
   update a set a.xxx=b.eee
   from a
   left  join b on a.bid=b.id
 
阿飛
2015/04/28

上一篇:利用oracle session的client_info記錄用戶登入信息
下一篇:使用full outer join 分析,校驗數據