update dsalesinvoicehdr set paymentterms = ( select pt.termcode from dsalesinvoicehdr dsh
inner join mg_subledger mp on mp.mg_subledgerid = dsh.customer
inner join mg_partytbill mb on mb.bsubledger = mp.subledgercode
left join payterm pt on pt.paytermid = mb.paymentterm)
ORA-01427:单行子查询返回多个行
如何解决此问题。请帮助
答案 0 :(得分:1)
将导致此错误,因为您的子查询返回了多条信息您的子查询返回了多行数据
您可以使用UPDATE
和JOIN
update
(
select pt.termcode,dsh.paymentterms
from dsalesinvoicehdr dsh
inner join mg_subledger mp on mp.mg_subledgerid = dsh.customer
inner join mg_partytbill mb on mb.bsubledger = mp.subledgercode
left join payterm pt on pt.paytermid = mb.paymentterm
) t
set t.termcode= t.paymentterms
答案 1 :(得分:0)
使用更新并加入队友!
update
(
select pt.termcode,dsh.paymentterms
from dsalesinvoicehdr dsh
inner join mg_subledger mp on mp.mg_subledgerid = dsh.customer
inner join mg_partytbill mb on mb.bsubledger = mp.subledgercode
left join payterm pt on pt.paytermid = mb.paymentterm
) tab
set tab.termcode= tab.paymentterms
答案 2 :(得分:0)
您需要选择一个值。常见的方法是聚合函数或where rownum = 1
:
update dsalesinvoicehdr
set paymentterms = (select pt.termcode
from dsalesinvoicehdr dsh inner join
mg_subledger mp
on mp.mg_subledgerid = dsh.customer inner join
mg_partytbill mb
on mb.bsubledger = mp.subledgercode join
payterm pt
on pt.paytermid = mb.paymentterm
where rownum = 1
);
子查询中不需要left join
。无论如何,不匹配将导致NULL
。