How to fix Ora-01427 single-row subquery returns more than one row in select?

前端 未结 3 600
迷失自我
迷失自我 2020-12-07 01:43

When i execute the following query, i get the message like

\"Ora-01427 single-row subquery returns more than one row\"

         


        
3条回答
  •  抹茶落季
    2020-12-07 02:06

    The only subquery appears to be this - try adding a ROWNUM limit to the where to be sure:

    (SELECT C.I_WORKDATE
             FROM T_COMPENSATION C
             WHERE C.I_COMPENSATEDDATE = A.I_REQDATE AND ROWNUM <= 1
             AND C.I_EMPID = A.I_EMPID)
    

    You do need to investigate why this isn't unique, however - e.g. the employee might have had more than one C.I_COMPENSATEDDATE on the matched date.

    For performance reasons, you should also see if the lookup subquery can be rearranged into an inner / left join, i.e.

     SELECT 
        ...
        REPLACE(TO_CHAR(C.I_WORKDATE, 'DD-Mon-YYYY'),
                ' ',
                '') AS WORKDATE,
        ...
     INNER JOIN T_EMPLOYEE_MS E
        ...
         LEFT OUTER JOIN T_COMPENSATION C
              ON C.I_COMPENSATEDDATE = A.I_REQDATE
              AND C.I_EMPID = A.I_EMPID
        ...
    

提交回复
热议问题