i getting error on:single-row subquery returns more than one row but yetserday i can update by code:
begin
for x in (select rowid as ib_rowid,T_T_INBOX.* from T_T_INBOX where MESSAGE_TYPE = 'LCSR')
loop
update T_T_INBOX
set T_T_INBOX.DOC_EXCHANGE_ID = (select doc.Id as Doc_Ex_id
from T_T_DOC_EXCHANGE doc
inner join T_T_INBOX ib on ib.KEY_FIELD1 = doc.REFERENCE_ID
inner join T_T_LICENSE_REJECT lire on ib.id = lire.MESSAGE_IN_ID
where ib.MESSAGE_TYPE = 'LCSR'
and ib.rowid = x.ib_rowid)
where rowid = x.ib_rowid;
end loop;
end;
Your inner select statement
select doc.Id as Doc_Ex_id
from T_T_DOC_EXCHANGE doc
inner join T_T_INBOX ib on ib.KEY_FIELD1 = doc.REFERENCE_ID
inner join T_T_LICENSE_REJECT lire on ib.id = lire.MESSAGE_IN_ID
where ib.MESSAGE_TYPE = 'LCSR'
and ib.rowid = x.ib_rowid
is returning more than one row (Possible cartesian product because of a missing join condition? Possible presence of two rows with same IDs?). You have to make sure that for every row in T_T_INBOX, the subquery returns exactly one row as the update statement cannot update a column to two different value. Hence the error.
Alternatively, you can use the oracle MERGE statement. It appears that you want to update the DOC_EXCHANGE_ID column in T_T_INBOX table by finding out the ID from the T_T_DOC_EXCHANGE table using some join condition on the T_T_LICENSE_REJECT table (I didn't understand this). But anyway, MERGE is designed exactly to do this without having to resort to PLSQL.
Maybe you want to give that a try.
解决此问题的理想方法是使用in而不是=,但是由于在此处尝试更新某些行,oracle会期望内部查询获得单个输出,并且如果使用in可能会在更新中引发一些错误。我建议使用游标获取需要更新的值,然后逐个执行,以循环方式进行
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.