加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

oracle 增删改查常技巧:

发布时间:2020-12-12 15:06:57 所属栏目:百科 来源:网络整理
导读:oracle 更新的三个方法: 1、T2表的SEX等于T2表的SEX。这个方法只能对T2表进行WHERE更新,不能对T1表进行WHERE更新 update temp2 t2 set t2.sex=(select t1.sex from temp1 t1 where t1.id=t2.id) where t2.age50 2、T2表的SEX等于T2表的SEX。这个方法可同时
oracle 更新的三个方法:
1、T2表的SEX等于T2表的SEX。这个方法只能对T2表进行WHERE更新,不能对T1表进行WHERE更新
update temp2 t2 set t2.sex=(select t1.sex from temp1 t1 where t1.id=t2.id)
where t2.age>50


2、T2表的SEX等于T2表的SEX。这个方法可同时对T1、T2表进行WHERE更新,且要更新的T2表中数据必须在T1中存在
update temp2 t2 set t2.sex=(select t1.sex from temp1 t1 where t1.id=t2.id)
where exists (select 1 from temp1 t1 where t1.id=t2.id and t1.age>50 and t2.age>50)


3、T2表的SEX等于T2表的SEX。这个方法可同时对T1、T2表进行WHERE更新,且要更新的T2表中数据必须在T1中存在
(这里由于使用了中间内存表,因此可以很方便地改变两表左、右、全、内连接的方法来控制要更新的T2表中的数据范围)
update (select t1.sex s1,t2.sex s2 from temp1 t1,temp2 t2 where t1.id=t2.id and t1.age>50 and t2.age>50)
set s2=s1

(注意:这个写法必须要求两张表关键条件的字段有唯一约束或主键约束,这也是为了保证查询的结果必须是一对一关系)


----未完待续-----

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读