我正在尝试将表 A 中的列 (REPT_IND) 更新为表 B 中的值,其中 A.ID = B.ID 和表 B 中的某些条件。表 B 中有一些重复项,但 REPT_IND 是相同的并且我仍然需要价值。我怎样才能在 Oracle 上做到这一点?任何提示表示赞赏谢谢!
以下代码有错误:
ORA-01427: single-row subquery returns more than one row
代码:
UPDATE A
SET REPT_IND= (
SELECT B.REPT_IND
FROM B
INNER JOIN A
ON B.ID = A.ID
where A.ID = B.ID
and B.job_type = 'P'
and B.FT_PT is not null
);
您也可以尝试merge
声明:
merge into a
using (
select a.id,max(b.rept_ind) rept_ind
from a left join b on a.id=b.id
where b.job_type = 'p'
and b.ft_pt is not null
) b
on (a.id=b.id)
when matched then update
set a.rept_ind=b.rept_ind;
或者,如果 b 中没有相关行,您不想将 a.rept_ind 设置为 null:
merge into a
using (
select b.id, max(b.rept_ind) rept_ind
from b
where
b.job_type = 'p'
and b.ft_pt is not null
group by b.id
) b
on (a.id=b.id)
when matched then update
set a.rept_ind=b.rept_ind;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句