执行update语句把两个表关联后把B表的一列更新A表中的某一列,
语句如下:
update a
set a.pd_mobile_phone = (select g_telephone from b where G_idcode = a.pd_idcard_no)
where exists (select 1 from b
where (G_idcode is not null or G_idcode <> '')
and G_idcode = a.pd_idcard_no
)
但提示上面的错误,请问这样的update 语句要如何写
1 楼
select g_telephone from b where G_idcode = a.pd_idcard_no
这条语句取出来有多条数据
而你在update时只能把其中一个值赋给 a.pd_mobile_phone
查查表之间的关联看
2 楼
就是select g_telephone from b where G_idcode = a.pd_idcard_no
返回多行了
3 楼
加上max()限制返回行数,另外G_idcode <> ''是多余的,这个表达式永远为false,oracle中''和null是一样的概念:
update a
set a.pd_mobile_phone = (select max(g_telephone) from b where G_idcode = a.pd_idcard_no)
where exists (select 1 from b
where G_idcode is not null
and G_idcode = a.pd_idcard_no
)