Merge有什么优点?

snailing1 2005-12-16 01:50:00
有两条语句,一条是
Merge into a using (select …… from b where ……) on a.id=b.id
when matched then update ……
when not matched then insert ……

一条是
truncate table a;
insert into a select …… from b where ……;
哪条更优呢?效率更高?
...全文
120 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
boydgmx 2006-02-23
  • 打赏
  • 举报
回复
A:

Merge into a using (select …… from b where ……) on a.id=b.id
when matched then update ……
when not matched then insert ……

B:
truncate table a;
insert into a select …… from b where ……;

A 是这样一个过程,逐行判断b表的数据,如果在a表中有满足条件的就更新,否则就添加
B 是这样一个过程,把b表中的数据添加到a表中

这是功能完全不同的两个语句,不能比较效率问题。

当然,如果你非要考虑效率问题,那么如果using子句中的b表是个大表,则Merge 的效率会非常低,因为merge是一条一条判断的。
snailing1 2005-12-16
  • 打赏
  • 举报
回复
自己支持一下

3,491

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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