我这有两个表tchouse1和tchouse2,这两个表都有unitnum和address,我想通过address这一列做参照把tchouse1的unitnum赋值到tchouse2的unitnum里,在sql里面的语句是这样的:update tchosue2
set t2.unitnum=t1.unitnum
from tchouse1 t1,tchouse2 t2
where t1.address=t2.address但是在oracle里面是没有update from这样的代码的,于是我在oracle里把语句修改为update tchouse2 t2 set t2.unitnum=(select distinct t1.unitnum from tchouse1 t1 where t1.address=t2.address) ;但是系统报错:单个子查询返回多个行,求解!
set t2.unitnum=t1.unitnum
from tchouse1 t1,tchouse2 t2
where t1.address=t2.address但是在oracle里面是没有update from这样的代码的,于是我在oracle里把语句修改为update tchouse2 t2 set t2.unitnum=(select distinct t1.unitnum from tchouse1 t1 where t1.address=t2.address) ;但是系统报错:单个子查询返回多个行,求解!
set (unitnum) = (select t1.unitnum from tchouse1 t1 where t1.address=t2.address)
--但是,这个时候你要注意的是,如果你的查询语句真的是返回多行的话,那么肯定是不行的,因为update的set值只能是一个,所以你首先需要验证下自己的数据,时候有一个address对应多个unitnum的情况,如果有一对多的情况,那么你想要更新哪一个值,必须指明,比如更新第一个,可以加上rownum = 1
select distinct t1.unitnum from tchouse1 t1 where t1.address=t2.address说明tchouse1 表的address不唯一,存在一个address对应多个不同的unitnum 可以改为
select min( t1.unitnum) from tchouse1 t1 where t1.address=t2.address