oracle 多表关联更新语句
来源:互联网 发布:it s high noon 编辑:程序博客网 时间:2024/06/03 15:43
在使用数据库进行更新操作时,我们可能会碰到一种情况,有表a和表b两张表,需要更新表b中的某个字段时,需要关联a b两表,将a表中的字段值赋值给b,此时执行sql语句如下:
update 表a set a.字段1 = (select b.字段1 from 表b where a.字段2=b.字段2) where exists
(select 1 from 表b where a.字段2=b.字段2)
但是执行语句时发现报了 ORA-01427 单行子查询返回多个行错误 ,观察sql执行发现是由于a.字段2 = b字段2 返回了多条a表中的数据(即对表b的字段2,为某值的数据在表a中有多条记录),此时需要先保证返回的b.字段1 为一条数据 才能执行update语句,可以使用下边的sql
update 表a set 表a.字段1 = (select t.字段1 from (select 表b.字段2,max(字段1)cc from 表b group by 字段2)t where 表a.字段2 = 表b.字段2) where exists(select 1 from 表b where a.字段2 = b.字段2)
以下是我使用到的一条sql语句
update hotel_member set hotel_member.cityid = ( select t.citity_id from (select aaa.hotelid ,max(cityid) citity_id from hotel_order aaa group by hotelid)t where hotel_member.hotelid = t.hotelid) where hotel_member.cityid is null
- oracle 多表关联更新语句
- oracle 多表关联 更新
- Oracle多表关联更新
- oracle多表关联更新
- Oracle多表关联更新
- ORACLE多表关联更新
- oracle多表关联更新
- 关于 oracle 多表关联更新的语句写法——仅仅是给自己看的
- ORACLE中的多表关联更新
- oracle UPDATE 多表关联更新
- oracle数据库多表关联更新sql
- Oracle 多表关联更新update
- Oracle Update多表关联更新
- Oracle多表关联更新(update多表关联)
- Oracle多表关联更新(update多表关联)
- 转:ORACLE 多表关联 UPDATE 语句
- ORACLE多表关联的update语句
- ORACLE 多表关联 UPDATE 语句
- 解决HTTP 302
- Nodejs express中创建ejs项目,解决express下默认创建jade,无法创建ejs问题
- 内核request_mem_region 和 ioremap的理解
- Javascript的简单用法
- 排序算法
- oracle 多表关联更新语句
- pthread_mutex_lock usage
- HDU 1869 (最短路)
- Bootmgr Part1 - SakiProject
- ubuntu 12.04 利用openswan实现ipsec vpn(lan-to-lan和host-to-lan)
- 【创业说】零经验接手APP运营推广,聊聊这两个月我是怎么熬过来的
- SAP BASIS顾问
- BLENDFUNCTION结构体
- 数据库分库分表