ORACLE执行语句返回‘单行子查询返回多个行’怎么解决?在线等
updateAaseta.txdz=(selecttxdzfromBbwherea.dwbh=b.dwbh),a.dwmc=(selectdwmcfromBbwherea...
update A a
set a.txdz=(select txdz from B b where a.dwbh=b.dwbh),
a.dwmc=(select dwmc from B b where a.dwbh=b.dwbh),
a.jhrxm=(select jhrxm from B b where a.dwbh=b.dwbh),
a.jhrzjhm=(select jhrzjhm from B b where a.dwbh=b.dwbh),
a.jhrsjhm=(select jhrsjhm from B b where a.dwbh=b.dwbh),
a.lxdh=(select lxdh from B b where a.dwbh=b.dwbh)
where a.flag='05' and exists (select 1 from B b where a.dwbh=b.dwbh); 展开
set a.txdz=(select txdz from B b where a.dwbh=b.dwbh),
a.dwmc=(select dwmc from B b where a.dwbh=b.dwbh),
a.jhrxm=(select jhrxm from B b where a.dwbh=b.dwbh),
a.jhrzjhm=(select jhrzjhm from B b where a.dwbh=b.dwbh),
a.jhrsjhm=(select jhrsjhm from B b where a.dwbh=b.dwbh),
a.lxdh=(select lxdh from B b where a.dwbh=b.dwbh)
where a.flag='05' and exists (select 1 from B b where a.dwbh=b.dwbh); 展开
1个回答
展开全部
这是你的条件有问题,而不是oracle的问题。改成这样就可以了
update A a set (a.txdz,a.dwmc,a.jhrxm,a.jhrzjhm,a.jhrsjhm,a.lxdh)=(select b.txdz,b.dwmc,b.jhrxm,b.jhrzjhm,b.jhrsjhm,b.lxdh from B b where a.dwbh=b.dwbh and rownum=1)
where a.flag='05' and exists (select 1 from B b where a.dwbh=b.dwbh);
但是修改结果是不是你想要的呢?
update A a set (a.txdz,a.dwmc,a.jhrxm,a.jhrzjhm,a.jhrsjhm,a.lxdh)=(select b.txdz,b.dwmc,b.jhrxm,b.jhrzjhm,b.jhrsjhm,b.lxdh from B b where a.dwbh=b.dwbh and rownum=1)
where a.flag='05' and exists (select 1 from B b where a.dwbh=b.dwbh);
但是修改结果是不是你想要的呢?
更多追问追答
追问
我只是想把B表的这些字段的值都赋给A表对应字段,但是BA表的dwbh是包含于的关系
追答
如果是a表的一条记录对应b表多条记录这个是做不到的,兄弟!不仅仅的oracle,其他数据库也是一样,update操作的每条记录必须一一对应,否则不能修改成功。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询