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
相关问答:
本来要写个update语句
update table_a A
set A.flag=1
where A.id in (select B.id from table_b B)
结果误写成
update table_a A
set A.flag=1
where ......
请问这个缓冲池是怎么回事啊?可以连接缓冲池利用其中的数据吧?怎么用?
这个是oracle自动做的,一般应用程序是操作不了的。
不能直接连接吗?
引用
不能直接连接吗?
不能
那缓冲池里的数据也不能查询 ......
我在创建数据库的时候用的名字为oracle10,但是创建好后,在默认的目录下显示的名称却是oracle10g,这是为什么?
你看的 10g是安装目录吧
SQL> select name from v$database;
NAME
---------
ORCL
......
在执行包的时候引用oracle spatial空间函数出错,出错情况如下
Errors in file
/user/oracle/app/oracle/admin/grid/udump/grid1_ora_143768.trc: ORA-29902:
error in executing ODCIIndexStart() routine ORA-0 ......
在系统运行的时候总是有一块磁盘始终闪红灯,进入系统后
#topas查看总是有一块磁盘%BUSY为90%以上,
数据库版本:oracle 9.2.0.7
数据文件挂载的节点:/oradata/pcs/ 逻辑卷号lv04
#lslv -l lv04
......