易截截图软件、单文件、免安装、纯绿色、仅160KB

Oracle多表连接更新

两个表A,B通过字段ID INNER JOIN连接,现想更新表B中的QTY值为表A的QTY值,但只更新这两个QTY不一样的部分,一样的不动。
晕, 一样的动不动有什么区别吗?

方式1, update

update a
set a.qty = (select qty from b where a.id = b.id)
where exists (select 1 from b where a.id = b.id and a.qty <> b.qty)

方式2, merge into

merge into a
using (select b.* from  a, b where a.id = b.id and a.qty <> b.qty ) b
on (a.id = b.id)
when matched then
update set a.qty = b.qty
when not matched then
  insert (a.id,a.qty)
  values(b.id,b.qty)

因为数据量太大,虽然没区别,但这样不是等于整个表更新了吗?

SQL code:

merge into B
using A
on(B.id = a.id)
when matched then
update set B.QTY=A.QTY where B.QTY<>A.QTY;




SQL code:
update a
set a.qty = (select qty from b where a.id = b.id)
where exists (select 1 from b where a.id = b.id and a.qty <> b.qty)


2楼 4楼哪个对?

都可以。一个是没有找到的情况下就为insert一条建议2楼

2楼很对啊

merge into B
using A
on(B.id = a.id)
when matched then
  update set B.QTY=A.QTY where


相关问答:

Oracle 数据导出问题 - Oracle / 高级技术

exp user/password@dbname file=c:\table.dmp tables=jbitaku,jbitakum grants=y
然後按回車鍵 說明:  user/password@dbname  分別表示用戶名,密碼和服務名 f ......

谁能推荐几本oracle的书或视频 - Oracle / 非技术区

谢谢
我也是想知道

me too

我 也 想 知 道 其 他 的,我 现 在 就 在 学 orcale 数 据 库,我 
用 的 是 赵 元 杰 编 的.......

个人觉得原理性的东西看一些官方文档可能会好一些 如果没有老师教 ......

linux下C语言开发oracle的问题。

两个文件1.PC,1.inc
1.PC有操作oracle数据库的 ,1.inc也有操作oracle数据库 
在其他数据中如informix 中$include 1.inc就可以使用了
在ORACLE数据库重 $include 1.inc不可用 EXEC SQL include 1.inc也不可 ......

ORACLE 分页 - Java / Web 开发

大家遇到ORACLE分页都是怎么处理的?
是用SQL语句分页?还是用可滚动的结果集分页?
希望大家能把代码贴出来。
最后大家感觉哪种效率高?为什么?
要是用hibernate的话,就不用管是不是oracle了。
我只知道orac ......

oracle与aix - Oracle / 高级技术

在系统运行的时候总是有一块磁盘始终闪红灯,进入系统后
#topas查看总是有一块磁盘%BUSY为90%以上,
数据库版本:oracle 9.2.0.7 
数据文件挂载的节点:/oradata/pcs/ 逻辑卷号lv04 
#lslv -l lv04 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号