0

我有一个查询:

SELECT     eo.mch_code, eo.mch_name, eo.serial_no, eo.category_id,
       eo.sup_mch_code, eo.GROUP_ID, eo.cost_center,
       (SELECT     e1.sup_mch_code
              FROM equipment_object e1
             WHERE e1.sup_mch_code LIKE 'OBIEKT-S/%'
        CONNECT BY PRIOR e1.sup_mch_code = e1.mch_code
        START WITH e1.mch_code = eo.mch_code) obiekt_s_kod,
       (SELECT e2.mch_name
          FROM equipment_all_object e2
         WHERE e2.mch_code =
                  (SELECT     e1.sup_mch_code
                         FROM equipment_object e1
                        WHERE e1.sup_mch_code LIKE
                                              'OBIEKT-S/%'
                   CONNECT BY PRIOR e1.sup_mch_code =
                                               e1.mch_code
                   START WITH e1.mch_code = eo.mch_code)) obiekt_s_nazwa
  FROM equipment_object eo
 WHERE eo.contract LIKE NVL (UPPER ('&umiejscowienie'), '%')
   AND eo.mch_code LIKE NVL (UPPER ('&obiekt_podrzedny'), '%')
   AND NVL (eo.cost_center, ' ') LIKE NVL (UPPER ('&MPK'), '%')
CONNECT BY PRIOR eo.mch_code = eo.sup_mch_code
START WITH eo.sup_mch_code LIKE UPPER ('&obiekt_nadrzedny')

但是当我编译这个查询时,我得到了错误:

ORA-01427: single-row subquery returns more than one row

哪里错了??我阅读了很多主题,但我不搜索我的问题

4

1 回答 1

1

好的,我解决了这个问题:)!

我必须插入条件:rownum =1

像这样的例子:

    SELECT     eo.mch_code, eo.mch_name, eo.serial_no, eo.category_id,
       eo.sup_mch_code, eo.GROUP_ID, eo.cost_center,
       (SELECT     e1.sup_mch_code
              FROM equipment_object e1
             WHERE e1.sup_mch_code LIKE 'OBIEKT-S/%'
             and rownum=1
        CONNECT BY PRIOR e1.sup_mch_code = e1.mch_code
        START WITH e1.mch_code = eo.mch_code) obiekt_s_kod,
       (SELECT e2.mch_name
          FROM equipment_all_object e2
         WHERE e2.mch_code =
                  (SELECT     e1.sup_mch_code
                         FROM equipment_object e1
                        WHERE e1.sup_mch_code LIKE
                                              'OBIEKT-S/%'
                                              and rownum=1
                   CONNECT BY PRIOR e1.sup_mch_code =
                                               e1.mch_code
                   START WITH e1.mch_code = eo.mch_code)) obiekt_s_nazwa
  FROM equipment_object eo
 WHERE eo.contract LIKE NVL (UPPER ('&umiejscowienie'), '%')
   AND eo.mch_code LIKE NVL (UPPER ('&obiekt_podrzedny'), '%')
   AND NVL (eo.cost_center, ' ') LIKE NVL (UPPER ('&MPK'), '%')
CONNECT BY PRIOR eo.mch_code = eo.sup_mch_code START WITH eo.sup_mch_code LIKE UPPER ('&obiekt_nadrzedny')
于 2013-09-20T11:32:17.253 回答