Oracle用left join更新数据

随风忘记 2012-06-13 03:12:14
在Oracle里面不可以用
update a set a.xxx=b.eee
from a left outer join b on a.bid=b.id
么?
在sql里面这样写感觉挺方便的,在Oracle里面怎样替换这样的写法哪?
...全文
3900 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
随风忘记 2012-06-19
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 的回复:]

引用 1 楼 的回复:
这种形式

SQL code


update a set a.xxx = (select b.eee from b where a.bid = b.id)

正解
[/Quote]

merge into a
using b
on (a.a=b.b)
when matched then update set xxxxx
when not matched then insert (xxx) values(xxx);
这个个人感觉更好一些
siriusraider 2012-06-18
  • 打赏
  • 举报
回复
原来没用过merge,MARK一下
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
这种形式

SQL code


update a set a.xxx = (select b.eee from b where a.bid = b.id)
[/Quote]
正解
  • 打赏
  • 举报
回复
楼主的写法是SQL Server的写法啊
  • 打赏
  • 举报
回复
merge 好
随风忘记 2012-06-17
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 的回复:]

引用 11 楼 的回复:

SQL code
merge into a
using b
on (a.a=b.b)
when matched then update set xxxxx
when not matched then insert (xxx) values(xxx);


又找到个方法,这样也可以


那是 看你会不会用merge 了 一般人用的……
[/Quote]
我用的感觉效率比第一种要好,尤其是在数据比较多的情况下
老王 2012-06-15
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 的回复:]
引用 11 楼 的回复:

SQL code
merge into a
using b
on (a.a=b.b)
when matched then update set xxxxx
when not matched then insert (xxx) values(xxx);


又找到个方法,这样也可以


那是 看你会不会用merge 了 一般人用的不多 但是用……
[/Quote]

merge 还可以累加
随风忘记 2012-06-14
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]

+1
引用 4 楼 的回复:
Update emp
Set(sal,comm) = (select sal,comm. From emp1 where emp.empno = emp1.empno)
找到方法了.这样可以
[/Quote]
不过感觉这样比sql里面慢很多
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 的回复:]

SQL code
merge into a
using b
on (a.a=b.b)
when matched then update set xxxxx
when not matched then insert (xxx) values(xxx);


又找到个方法,这样也可以
[/Quote]

那是 看你会不会用merge 了 一般人用的不多 但是用处也蛮大的 但是效率还是没第一种好
勿勿 2012-06-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
这种形式

SQL code

update a set a.xxx = (select b.eee from b where a.bid = b.id)
[/Quote]+1
随风忘记 2012-06-14
  • 打赏
  • 举报
回复
merge into a 
using b
on (a.a=b.b)
when matched then update set xxxxx
when not matched then insert (xxx) values(xxx);

又找到个方法,这样也可以
hellen_99010 2012-06-13
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 的回复:]

引用楼主 的回复:
在Oracle里面不可以用
update a set a.xxx=b.eee
from a left outer join b on a.bid=b.id
么?
在sql里面这样写感觉挺方便的,在Oracle里面怎样替换这样的写法哪?

update a set a.xxx=(select b.eee
from a,b where a.bid(+)=b.id……
[/Quote]
效果是一样的。
ray_suen 2012-06-13
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
在Oracle里面不可以用
update a set a.xxx=b.eee
from a left outer join b on a.bid=b.id
么?
在sql里面这样写感觉挺方便的,在Oracle里面怎样替换这样的写法哪?
[/Quote]
update a set a.xxx=(select b.eee
from a,b where a.bid(+)=b.id)
ray_suen 2012-06-13
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
在Oracle里面不可以用
update a set a.xxx=b.eee
from a left outer join b on a.bid=b.id
么?
在sql里面这样写感觉挺方便的,在Oracle里面怎样替换这样的写法哪?
[/Quote]

左右关联在oracle里面用+号
update a set a.xxx=b.eee
from a,b where a.bid(+)=b.id
小德 2012-06-13
  • 打赏
  • 举报
回复
+1
[Quote=引用 4 楼 的回复:]
 Update emp
  Set(sal,comm) = (select sal,comm. From emp1 where emp.empno = emp1.empno)
找到方法了.这样可以
[/Quote]
  • 打赏
  • 举报
回复
嗯 oracle里面都是连续的方式操作的

和into赋值差不多模式
随风忘记 2012-06-13
  • 打赏
  • 举报
回复
 Update emp
  Set(sal,comm) = (select sal,comm. From emp1 where emp.empno = emp1.empno)
找到方法了.这样可以
随风忘记 2012-06-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

这种形式
SQL code

update a set a.xxx = (select b.eee from b where a.bid = b.id)
[/Quote]
这样一次只能修改一个字段,
如果我想修改多个字段的话不好改
  • 打赏
  • 举报
回复
oracle中 set前面只能存在一个表 后面也不能跟from 逻辑在子查询中处理
  • 打赏
  • 举报
回复
这种形式

update a set a.xxx = (select b.eee from b where a.bid = b.id)

17,088

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧