简体   繁体   中英

ORA-01427 error when trying to update tables

I'm trying to update a row in one table with one from another, and I'm getting the titled error. (ORA-01427: single-row subquery returns more than one row)

update T1
set (Created) = (select to_date('01011900000000','MMDDYYYYHH24MISS') + T2.nsample from T2 left join T3 on T3.ID = T2.DIMENSION_ID where T3.DIMENSION = 'Time' and T2.Subgroup_id = T1.ID)

where exists
(select 1 from T2 right join T3 on T2.DIMENSION_ID = T3.ID where T3.DIMENSION = 'Time' and T1.ID = T2.Subgroup_ID)

I believe this to be due to there being duplicate subgroup_ID's in T2, however if I try and use another subquery to try and force only distinct values like:

Update T1
set (Created) = (Select TEMP from (select  distinct Subgroup_ID as ID , to_date('01011900000000','MMDDYYYYHH24MISS') + T2.nsample as TEMP from T2 inner join T3 on T3.ID = T2.DIMENSION_ID where T3.DIMENSION = 'Time') T4 where T1.ID = T4.ID)

I still retain the same error.

I'm incredibly new to all of this and would really appreciate any guidance.

Thanks

ORA-01427: Subquery returns more than one row

That's cause your said subquery returning more than 1 record. Change your query like below

update T1
set (Created) = (
select to_date('01011900000000','MMDDYYYYHH24MISS') + T2.nsample 
from T2 
left join T3 on T3.ID = T2.DIMENSION_ID  and T3.DIMENSION = 'Time' 
left join T1 on T2.Subgroup_id = T1.ID
order by T2.Subgroup_id
OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY;
);

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