0

为什么我收到错误消息?

ORA-01427: 单行子查询使用此查询返回多行

UPDATE JOB_TASK JT1
   SET JT1.job_task_status_id =
          (SELECT JTS1.JOB_TASK_STATUS_ID
             FROM MAXIMO_WO MW1
                  INNER JOIN job_task_status jts1
                     ON MW1.STATUS = jts1.description
                     INNER JOIN JOB_TASK JT1
                     ON jt1.job_task_id = mw1.wonum)
WHERE   JT1.JOB_TASK_STATUS_ID IN
          (SELECT JTS.JOB_TASK_STATUS_ID
             FROM JOB_TASK_STATUS JTS,
                  JOB_TASK JT,
                  MAXIMO_WO MW,
                  WORK_ORDER_CONTROL WOC
            WHERE     JT.JOB_TASK_ID = MW.WONUM
                  AND JT.JOB_TASK_STATUS_ID = JTS.JOB_TASK_STATUS_ID
                  AND JT.WORK_ORDER_ID = WOC.WORK_ORDER_ID
                  and jt.job_task_id = mw.wonum
                  AND MW.STATUS IN
                         ('APPR',
                          'SCHED',
                          'INPRG',
                          'FNACCEPT',
                          'WMATL',
                          'WKCOMP',
                          'COMP')
                  AND WOC.COMPANY_ID = '21'
                  AND MW.SITEID <> 'NUCDEV'
                  AND DECODE (
                         INSTR (JTS.DESCRIPTION, '-', 1),
                         0, JTS.DESCRIPTION,
                         SUBSTR (JTS.DESCRIPTION,
                                 1,
                                 (INSTR (JTS.DESCRIPTION, '-', 1) - 1))) <>
                         MW.STATUS
                  AND JT.LEVEL_NUMBER = '3'
                  AND MW.STATUSDATE < SYSDATE - 1
                  AND MW.WONUM <> 'UNDEFINED')
4

2 回答 2

2

我怀疑你真的想要语句的 SET 部分中的子选择。尝试这样的事情:

 UPDATE JT1
    SET JT1.job_task_status_id = JTS1.JOB_TASK_STATUS_ID
 FROM MAXIMO_WO MW1
      INNER JOIN job_task_status jts1
            ON MW1.STATUS = jts1.description
      INNER JOIN JOB_TASK JT1
            ON jt1.job_task_id = mw1.wonum
 WHERE   JT1.JOB_TASK_STATUS_ID IN
      (SELECT JTS.JOB_TASK_STATUS_ID
         FROM JOB_TASK_STATUS JTS,
              JOB_TASK JT,
              MAXIMO_WO MW,
              WORK_ORDER_CONTROL WOC
        WHERE     JT.JOB_TASK_ID = MW.WONUM
              AND JT.JOB_TASK_STATUS_ID = JTS.JOB_TASK_STATUS_ID
              AND JT.WORK_ORDER_ID = WOC.WORK_ORDER_ID
              and jt.job_task_id = mw.wonum
              AND MW.STATUS IN
                     ('APPR',
                      'SCHED',
                      'INPRG',
                      'FNACCEPT',
                      'WMATL',
                      'WKCOMP',
                      'COMP')
              AND WOC.COMPANY_ID = '21'
              AND MW.SITEID <> 'NUCDEV'
              AND DECODE (
                     INSTR (JTS.DESCRIPTION, '-', 1),
                     0, JTS.DESCRIPTION,
                     SUBSTR (JTS.DESCRIPTION,
                             1,
                             (INSTR (JTS.DESCRIPTION, '-', 1) - 1))) <>
                     MW.STATUS
              AND JT.LEVEL_NUMBER = '3'
              AND MW.STATUSDATE < SYSDATE - 1
              AND MW.WONUM <> 'UNDEFINED')
于 2013-04-10T16:02:20.113 回答
0

正如错误所示,您的 SET 语句中的子查询返回多个值:

SELECT JTS1.JOB_TASK_STATUS_ID
             FROM MAXIMO_WO MW1
                  INNER JOIN job_task_status jts1
                     ON MW1.STATUS = jts1.description
                     INNER JOIN JOB_TASK JT1
                     ON jt1.job_task_id = mw1.wonum

因为这个查询无论如何都没有连接到您的外部 UPDATE 语句。我知道,我知道,您对 JOB_TASK 表使用了相同的别名!但就 Oracle 而言,这只是巧合,因为您将 JOB_TASK 表重新加入到查询中。这个查询基本上会返回每个job_task、它的工单数据和它的任务状态。

您需要的只是引用您的外部别名:

UPDATE JOB_TASK JT1
   SET JT1.job_task_status_id =
          (SELECT JTS1.JOB_TASK_STATUS_ID
             FROM MAXIMO_WO MW1
                  INNER JOIN job_task_status jts1
                     ON MW1.STATUS = jts1.description
                     and MW1.MoNum = jt1.job_task_id )
... 

这将正确使用您外部 JOB_TASK 的 job_task_id 来获取其 task_status_id。

于 2013-04-10T16:00:56.170 回答