简体   繁体   中英

ORA-01427: single-row subquery returns more than one row - issue

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: single-row subquery returns more than one row

how to resolve this issue. pls help

Will cause this error because your subquery returns multiple pieces of information Your subquery return multi-row data

You can use UPDATE and 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  

Use update and join mate!!

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 

You need to select one of the values. To common methods are an aggregation function or 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
                       );

You don't need the left join in the subquery. Non-matches will result in NULL anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM