2013-07-08 158 views
0

我的查詢如下:ORA-01427:單行子查詢返回不止一行

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:單行子查詢返回不止一行如果儘管它們具有不同的headid值,但在這種情況下不應出現這種情況,請告知這種情況,我在emppirmesion中有多行具有相同的clasissymbolicname。

+0

如果'emppirmesion'中的多行具有相同的'classisymbolicname',你會得到不同的'headid'值嗎?在這種情況下,您的查詢應該發生什麼情況,它應該是隨機的還是第一個? – beny23

+0

@ beny23,我確實有不止一行emppirmesion與相同classisymbolicname和不同headid值,但執行查詢時,我只得到異常。 –

+0

是的,我的觀點是你會得到異常,因爲Oracle期望'START WITH = single value',但是你的查詢提供了'START WITH = multiple values',所以你將不得不重新設計你的查詢,但不知道是什麼你正在努力實現,這有點困難... – beny23

回答

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') 

和它的工作原理精細。