我试图更新表中的两行。 如果我使用过:
update ERNTESTUPDATE a
set (date_loaded, acad_career) = (select distinct b.date_loaded, b.acad_career
from PS_STDNT_ENRL b
where rownum=1)
where to_char(date_created) = to_char(trunc(sysdate))
;
我将2行更新为
11/29/18 UGRD
11/29/18 UGRD
如果我使用过
:update ERNTESTUPDATE a
set (date_loaded, acad_career) = (select distinct b.date_loaded, b.acad_career
from PS_STDNT_ENRL b
where a.date_loaded = b.date_loaded )
where to_char(date_created) = to_char(trunc(sysdate))
;
我遇到错误
单行子查询返回多行
如何获得如下结果:
11/29/18 UGRD
11/29/18 GRAD
谢谢你, 凯特
答案 0 :(得分:0)
子查询需要返回单行。当您在第一个条件中包含条件rownum=1
时,效果很好:
select distinct b.date_loaded, b.acad_career
from PS_STDNT_ENRL b
where rownum=1 -- this filter makes sure only one row is returned
如果删除该条件,则子查询将返回多行,这将使整个UPDATE
失败。