我的查询如下:
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')
我收到异常 ORA-01427:单行子查询返回多行如果我在emppirmesion中有多个行具有相同的clasisymbolicname,尽管它们具有不同的headid值和在这种情况下不应发生此异常,请提供相关建议。
答案 0 :(得分:0)
问题是START WITH期望单值并且我的子查询返回多个值,所以我更改了的查询:
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')
以强>:
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')
它工作正常。