0

我正在尝试执行下一个查询:

 SELECT  
   PROMO_PLAN.promo_plan_id,  
   PROMO_PLAN.promo_plan_name,  
   PROMO.promo_category_code,  
   PROMO.promo_id,  
   PROMO.allow_plan_code,  
   PROMO_PLAN.event_type_code,  
   ( SELECT  
     NVL(PROMO_MAX_TIMING_DURATION_VW.duration, 900) 
    FROM  
   promo_max_timing_duration_vw 
    WHERE  
   PROMO_PLAN.promo_plan_id = PROMO_MAX_TIMING_DURATION_VW.promo_plan_id) 
  AS duration,  
   PROMO_PLAN.start_date,  
   PROMO_PLAN.end_date,  
   PROMO_PLAN.day_type_id 
  FROM  
   promo_plan,  
   promo 

 WHERE  
   PROMO_PLAN.promo_plan_id <> -1 
    AND PROMO_PLAN.promo_id = PROMO.promo_id 
    AND PROMO_PLAN.promo_plan_id = 18150
   AND '27/09/2012' BETWEEN PROMO_PLAN.start_date AND PROMO_PLAN.end_date
   AND (PROMO_PLAN.day_type_id = 1307001 

   OR PROMO_PLAN.day_type_id = -1)
   AND (PROMO_PLAN.promo_target_id = -1 
    OR  EXISTS ( 
      SELECT  
       1 
      FROM  
       promo_plan_channel 
      WHERE  
       PROMO_PLAN_CHANNEL.promo_plan_id = PROMO_PLAN.promo_plan_id 
        AND PROMO_PLAN_CHANNEL.channel_id = 10829))

我收到错误消息:ORA-01427:单行子查询返回多于一行

我试图更改最后一个子查询,但它什么也没改变。

有人可以告诉我如何解决吗?

谢谢

4

3 回答 3

4

你的问题很可能是

 ( SELECT  
     NVL(PROMO_MAX_TIMING_DURATION_VW.duration, 900) 
    FROM  
   promo_max_timing_duration_vw 
    WHERE  
   PROMO_PLAN.promo_plan_id = PROMO_MAX_TIMING_DURATION_VW.promo_plan_id) 

返回多行。

于 2013-06-30T11:58:41.397 回答
2

如果删除此部分,查询会运行吗?

   ( SELECT  
     NVL(PROMO_MAX_TIMING_DURATION_VW.duration, 900) 
    FROM  
   promo_max_timing_duration_vw 
    WHERE  
   PROMO_PLAN.promo_plan_id = PROMO_MAX_TIMING_DURATION_VW.promo_plan_id) 

如果是这样,你知道罪魁祸首。修改此子查询以最多返回一行。

于 2013-06-30T11:58:53.543 回答
0

试试这样:

SELECT  
   PROMO_PLAN.promo_plan_id,  
   PROMO_PLAN.promo_plan_name,  
   PROMO.promo_category_code,  
   PROMO.promo_id,  
   PROMO.allow_plan_code,  
   PROMO_PLAN.event_type_code,  
   p.d AS duration,  
   PROMO_PLAN.start_date,  
   PROMO_PLAN.end_date,  
   PROMO_PLAN.day_type_id 
  FROM  
   promo_plan,  
   promo, 
   ( SELECT NVL(PROMO_MAX_TIMING_DURATION_VW.duration, 900) d, promo_plan_id
    FROM promo_max_timing_duration_vw 
   ) p
 WHERE  
   PROMO_PLAN.promo_plan_id <> -1 
    AND PROMO_PLAN.promo_id = PROMO.promo_id 
    AND PROMO_PLAN.promo_plan_id = 18150
    and PROMO_PLAN.promo_plan_id = p.promo_plan_id
   AND '27/09/2012' BETWEEN PROMO_PLAN.start_date AND PROMO_PLAN.end_date
   AND (PROMO_PLAN.day_type_id = 1307001 

   OR PROMO_PLAN.day_type_id = -1)
   AND (PROMO_PLAN.promo_target_id = -1 
    OR  EXISTS ( 
      SELECT  
       1 
      FROM  
       promo_plan_channel 
      WHERE  
       PROMO_PLAN_CHANNEL.promo_plan_id = PROMO_PLAN.promo_plan_id 
        AND PROMO_PLAN_CHANNEL.channel_id = 10829))
于 2013-06-30T12:06:38.667 回答