我正在尝试将一个表中的一行更新为另一个表,并且我得到了标题错误。 (ORA-01427:单行子查询返回多行)
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)
我认为这是由于T2中存在重复的subgroup_ID,但是如果我尝试使用另一个子查询来尝试仅强制使用不同的值:
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)
我仍然保留相同的错误。
我对这一切都非常新,并且非常感谢任何指导。
由于
答案 0 :(得分:1)
ORA-01427:子查询返回多行
这是因为你说的子查询返回超过1条记录。更改您的查询,如下所示
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;
);