问题
my query is as follows:
SELECT DISTINCT *
FROM (SELECT depts."ID", depts.arabic_description
FROM sng_v_org_unit_departments depts
INNER JOIN (SELECT "ID", arabic_description, ouh_id
FROM sng_v_org_unit_headers
START WITH "ID" =
(SELECT headid
FROM emppirmesion per
inner join empldabdetail empinfo
on per.emprecid = empinfo.recid
where lower(empinfo.shortname) = lower('ibmadmin') and
per.headid > 0 and
per.clasisymbolicname = 'SoHiring')
CONNECT BY PRIOR "ID" = ouh_id) heads
ON depts.ouh_id = heads."ID"
UNION
SELECT per.depid, depts.arabic_description
FROM emppirmesion per
inner join empldabdetail empinfo on per.emprecid = empinfo.recid
inner join sng_v_org_unit_departments depts on per.depid = depts."ID"
where lower(empinfo.shortname) = lower('ibmadmin') and
per.depid > 0 and
per.clasisymbolicname = 'SoHiring')
I am getting an exception ORA-01427: single-row subquery returns more than one row if i have more than one row in the emppirmesion that have the same clasisymbolicname although they have differnet headid values and this exception shouldn't occur in this case, please advise about that.
回答1:
Issue was the START WITH expects single value and my subquery was returning multiple values, so i changed the query from:
START WITH "ID" =
(SELECT headid
FROM emppirmesion per
inner join empldabdetail empinfo
on per.emprecid = empinfo.recid
where lower(empinfo.shortname) = lower('ibmadmin') and
per.headid > 0 and
per.clasisymbolicname = 'SoHiring')
to:
Where "ID" in
(SELECT headid
FROM emppirmesion per
inner join empldabdetail empinfo
on per.emprecid = empinfo.recid
where lower(empinfo.shortname) = lower('ibmadmin') and
per.headid > 0 and
per.clasisymbolicname = 'SoHiring')
and it works fine.
来源:https://stackoverflow.com/questions/17521985/ora-01427-single-row-subquery-returns-more-than-one-row