Home > Database > Mysql Tutorial > body text

Oracle单行子查询返回多于一个行解决方法

WBOY
Release: 2016-06-07 16:58:57
Original
3183 people have browsed it

举个例子:update table1 t1 set t1.name = (select t2.name from table2 t2 where t2.age=20)出现错误的原因:子查询多于

举个例子:update table1 t1 set t1.name = (select  t2.name  from  table2  t2  where  t2.age=20)

出现错误的原因:子查询多于一条记录。

如果想批量更新数据则可以嵌套,例如下面的sql,当然还可以继续嵌套。

update table1 t1 set t1.name  =(select t3.name,t3.id from (select  t2.name  from  table2  t2  where  t2.age=20)t3  where t3.id=t1.id)

紧挨着“=”号后面的小括号里子查询的返回结果必须只有一条记录,,但是里面可以返回多个,也就是说可以批量更新。

linux

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!