/*涉及到多个表关联的例子,我们以三个表为例,只是作更新处理,不做插入处理。当然也可以只做插入处理*/
--将fzq1表中女生记录的成绩+1,没有直接去sex字段。而是fzq和fzq2关联。
merge into fzq1 aa --fzq1表是需要更新的表
using (select fzq.id,fzq.chengji
from fzq join fzq2
on fzq.id=fzq2.id) bb -- 数据集
on (aa.id=bb.id) --关联条件
when matched then --匹配关联条件,作更新处理
update set
aa.chengji=bb.chengji+1
--可以自行查询fzq1表。
/*不能做的事情*/
merge into fzq1 aa
using fzq bb
on (aa.id=bb.id)
when matched then
update set
aa.id=bb.id+1
/*系统提示:
ORA-38104: Columns referenced in the ON Clause cannot be updated: "AA"."ID"
我们不能更新on (aa.id=bb.id)关联条件中的字段*/
update fzq1
set id=(select id+1 from fzq where fzq.id=fzq1.id)
where id in
(select id from fzq)
--使用update就可以更新,如果有更好的方法,谢谢反馈!
| 广告合作:400-664-0084 全国热线:400-664-0084 Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号 珠峰网 版权所有 All Rights Reserved
|