sql ora-01427错误单个查询返回多行

时间:2014-02-18 10:27:14

标签: sql oracle nvl

查询

SELECT DISTINCT st_str_hry.id_str_rt,
  decode(co_strgp.nm_strgp,'HOLLAND & BARRETT','H&B','GNC UK','GNC')brandName
FROM co_strgp,
     st_str_hry
WHERE co_strgp.id_strgp=st_str_hry.id_strgp
  AND co_strgp.nm_strgp in(nvl(:brandName,
                                 (SELECT co_strgp.nm_strgp
                                  FROM co_strgp
                                  WHERE id_strgp_lv='2'
                                    AND id_strgp in
                                      (SELECT DISTINCT id_strgp
                                       FROM st_str_hry
                                       WHERE id_str_rt in
                                           (SELECT DISTINCT id_str_rt
                                            FROM NBTY_TR_LTM_AER_RTN)))));

此处nvl部分正在抛出ora-01427 error,其中显示single query returning multiple rows

2 个答案:

答案 0 :(得分:0)

查询

SELECT co_strgp.nm_strgp
  FROM co_strgp
 WHERE id_strgp_lv='2'
   AND id_strgp in (SELECT DISTINCT id_strgp
                      FROM st_str_hry
                     WHERE id_str_rt in (SELECT DISTINCT id_str_rt
                                           FROM NBTY_TR_LTM_AER_RTN))

返回多行,但必须只返回一行

答案 1 :(得分:0)

将包含子查询的代码部分重写为:

AND co_strgp.nm_strgp in(
           ( SELECT nvl( :brandName,co_strgp.nm_strgp )
             FROM co_strgp
             WHERE id_strgp_lv='2'
               AND id_strgp in
                   (SELECT DISTINCT id_strgp
                    FROM st_str_hry
                    WHERE id_str_rt in
                          (SELECT DISTINCT id_str_rt
                            FROM NBTY_TR_LTM_AER_RTN)))));