Chinaunix首页 | 论坛 | 博客
  • 博客访问: 410860
  • 博文数量: 66
  • 博客积分: 1416
  • 博客等级: 上尉
  • 技术积分: 922
  • 用 户 组: 普通用户
  • 注册时间: 2006-09-16 10:37
个人简介

高級Oracle DBA,善長Linux系統維運以及Oracle數據庫管理,開發,調優. 具有多年PL/SQL開發經驗.

文章分类

全部博文(66)

文章存档

2015年(9)

2014年(4)

2013年(5)

2010年(1)

2009年(3)

2008年(6)

2007年(30)

2006年(8)

我的朋友

分类: Oracle

2015-04-28 14:46:38

 
  我這里說的,用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

阅读(4332) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~