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


举个例子: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)

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

相关内容