文章分类 | 推荐文章 | 最新文章 | 热点文章 | 最新软件 | 精品软件 | 下载排行 | 推荐下载 | 免费看大片 | WPS | 杀毒软件
清风网络
首 页 软件下载 网络学院 数码学院
QQ 电脑入门 游戏 操作系统 图形处理 办公软件 媒体动画 精文荟萃 工具软件 网络编程 程序开发 网络技术 认证考试 网站建设 文章专栏
当前位置:清风网络学院程序开发Oracleoracle update多表关联
精品推荐
特别推荐
·常用数据库比较
·ODBC API常用函数诠释
·提高ORACLE数据库的查询统计速度
·细化解析:Oracle使用的hints调整机制
·解析Oracle/Oracle Forms 的多用途代码
·从Oracle的FORM中调用REPORT的实用技巧
·Oracle SQL精妙SQL语句讲解
·ORACLE学习笔记--性能优化四
·ORACLE常用傻瓜问题1000问
·ORACLE常见错误代码的分析与解决之二
热点TOP10
·常用数据库比较
·性能分析工具的使用
·Oracle数据库重做日志文件丢失后的恢复
·细化解析:Oracle使用的hints调整机制
·监控Oracle数据库的常用shell脚本
·ORA-01092: ORACLE 例程终止。强行断开连接
·oracle数据库 exp/imp命令详解
·解析Oracle/Oracle Forms 的多用途代码
·Oracle数据库不同版本间用exp来导数据
·细化解析:Oracle数据库后台进程的功能

oracle update多表关联

日期:2008年5月11日 作者: 查看:[大字体 中字体 小字体]


UPDATE A.A3 = A.A3+B.B3 的问题

表A 结构 : A1 , A2 ,A3
表B 结构: B1,  B2,  B3
其中 A1 ,B1 为PK ,切值相同 就是可以使用A1 = B1 了.

请问用SQL 语句或过程该如何实现如下的功能???

更新A 表的 A3 ,用A.A3 与B.B3之和更新.

3>update A
set A3 = (select A.A3 + B.B3 from B where A.A1 = B.B1) ;

7>update (select a1,a3,b1,b3 from a,b where a1=b1) set a3=a3+b3


开执行计划, 谈论效率是没有太多的意义的^_^..


三楼的写法与7楼的写法得到的结果是不同的.

三楼的写法会更新所有记录, 而7楼的写法只修改两者相交的相关记录信息.

7楼的写法可以更加容易的控制这条update语句的执行计划, 不过要求B表必须在对应的字段上有主键索引:) , 在B表在对应字段上有主键索引的时候, 建议使用7楼的写法.

可以参考一下这个帖子^_^

http://www.cnoug.org/viewthread.php?tid=44070
(测试没有成功..不知道怎么搞的.)
参考了下面的:
非常佩服。抱着学习的态度,重写了一下三楼的,在没有主键的情况,请指教:
update a
set a3=(select a3+b3 from b where a1=b1)
where a1=(select b1 from b where a1=b1)
如下:
update con_eme_on20050309 a set a.con_price=(select a.con_price+(b.annuity-a.annuity)+(b.nojob-a.nojob)+(b.medicare-a.medicare)+(b.birthfee-a.birthfee)+(b.bruisefee-a.bruisefee) from con_eme_on200404 b where a.emp_cod=b.emp_cod and a.if_act='1' and a.emp_base!=b.emp_base),a.emp_base=(select b.emp_base from con_eme_on200404 b where a.emp_cod=b.emp_cod and a.if_act='1' and a.emp_base!=b.emp_base),a.annuity=(select b.annuity from con_eme_on200404 b where a.emp_cod=b.emp_cod and a.if_act='1' and a.emp_base!=b.emp_base),a.nojob=(select b.nojob from con_eme_on200404 b where a.emp_cod=b.emp_cod and a.if_act='1' and a.emp_base!=b.emp_base),a.medicare=(select b.medicare from con_eme_on200404 b where a.emp_cod=b.emp_cod and a.if_act='1' and a.emp_base!=b.emp_base),a.birthfee=(select b.birthfee from con_eme_on200404 b where a.emp_cod=b.emp_cod and a.if_act='1' and a.emp_base!=b.emp_base),a.bruisefee=(select b.bruisefee from con_eme_on200404 b where a.emp_cod=b.emp_cod and a.if_act='1' and a.emp_base!=b.emp_base),a.nojobbase=(select b.nojobbase from con_eme_on200404 b where a.emp_cod=b.emp_cod and a.if_act='1' and a.emp_base!=b.emp_base),a.mediabase=(select b.mediabase from con_eme_on200404 b where a.emp_cod=b.emp_cod and a.if_act='1' and a.emp_base!=b.emp_base),a.birthbase=(select b.birthbase from con_eme_on200404 b where a.emp_cod=b.emp_cod and a.if_act='1' and a.emp_base!=b.emp_base),a.bruisebase=(select b.bruisebase from con_eme_on200404 b where a.emp_cod=b.emp_cod and a.if_act='1' and a.emp_base!=b.emp_base)
where a.emp_cod in(select b.emp_cod from con_eme_on200404 b where a.emp_cod=b.emp_cod and a.if_act='1' and a.emp_base!=b.emp_base)

[1] [2] 下一页 




上一篇:简便实现Oracle数据库文件移动方法

下一篇:看看葫芦里的药 ORACLE性能调优原则

相关文章:
·Oracle数据库重做日志文件丢失后的恢复
·上下文关联广告清单(内文广告)推荐
·细化解析:Oracle使用的hints调整机制
·监控Oracle数据库的常用shell脚本
·ORA-01092: ORACLE 例程终止。强行断开连接
·oracle数据库 exp/imp命令详解
·巧用Excel函数来实现工作表间的数据关联
·文件关联型木马的特殊化查杀
·解析Oracle/Oracle Forms 的多用途代码
·Oracle数据库不同版本间用exp来导数据
相关软件:
·Effective Oracle by design(脚本)
·Oracle认证考试百宝箱V 2.0
·Oracle9i Performance Tuning
·ORACLE数据管理工具V1.0.0.6
·Oracle 1z0-501 V3 考试试题题库
·Oracle技术资料大全
·Oracle官方文档CHM合集-Database参考手册
·Oracle官方文档CHM合集-Oracle10g错误代码
·TestKing Oracle 1z0-033 V23
·Oracle8i Internal Services(脚本)

特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
[打印本页] [关闭窗口] 转载请注明来源:http://www.vipcn.com
| 帮助(?) | 版权声明 | 友情连接 | 关于我们 | 信息发布
Copyright 2007 www.vipcn.com All Rights Reserved. 鄂ICP备05000083号Powered by:vipcn