过滤器参数无法正常工作

时间:2018-06-26 07:49:33

标签: sql oracle

我只能获取第一个过滤器“ SEL”的数据,但是当我们输入“购买”或“全部”时,数据就不会出现。

如果我为每个过滤器一个一个地运行条件,则它正在工作。但是在AND OR循环中,它无法按预期工作。

我正在将相同的值传递给所有3个参数。因此一次只能使用一个过滤器,并根据传递的值获取结果

AND
      (
          ('&psRate_type') = 'SEL' AND  PCP.charge_calculation_method = 'R' AND RPH.RP_RECORD_ID = PCP.CHARGE_RATEPROF_RECORD_ID
      OR

           ('&psRate_type') = 'BUY' AND  PCP.cost_calculation_method = 'R' AND RPH.RP_RECORD_ID = PCP.COST_RATEPROF_RECORD_ID
      OR

           ('&psRate_type') = 'All' AND 
                                         (RPH.RATE_TYPE = 'SEL' AND PCP.charge_calculation_method = 'R' AND RPH.RP_RECORD_ID = PCP.COST_RATEPROF_RECORD_ID)  
                                         OR
                                         ((RPH.RATE_TYPE = 'BUY') AND PCP.cost_calculation_method = 'R' AND RPH.RP_RECORD_ID = PCP.COST_RATEPROF_RECORD_ID)
      )

3 个答案:

答案 0 :(得分:1)

您搞砸了AND和OR。如我所见,您想分离3个过滤器。 尝试以下方法:

AND
  (
      (
        ('&psRate_type') = 'SEL' AND  PCP.charge_calculation_method = 'R' AND RPH.RP_RECORD_ID = PCP.CHARGE_RATEPROF_RECORD_ID
      )
  OR
      (
        ('&psRate_type') = 'BUY' AND  PCP.cost_calculation_method = 'R' AND RPH.RP_RECORD_ID = PCP.COST_RATEPROF_RECORD_ID
      )
  OR
      (
        ('&psRate_type') = 'All' AND 
                                     (RPH.RATE_TYPE = 'SEL' AND PCP.charge_calculation_method = 'R' AND RPH.RP_RECORD_ID = PCP.COST_RATEPROF_RECORD_ID)  
                                     OR
                                     (RPH.RATE_TYPE = 'BUY' AND PCP.cost_calculation_method = 'R' AND RPH.RP_RECORD_ID = PCP.COST_RATEPROF_RECORD_ID)
      )  
  )

答案 1 :(得分:1)

如果您将“第一或”与“买入”,第二或“ SEL”等放在一起,它是否有效?

答案 2 :(得分:0)

使用ORAND时,应查看评估的优先级。

因此,请使用括号确保每次都评估整个条件。

AND
      (    ('&psRate_type' = 'SEL' AND  PCP.charge_calculation_method = 'R' AND RPH.RP_RECORD_ID = PCP.CHARGE_RATEPROF_RECORD_ID)
        OR ('&psRate_type' = 'BUY' AND  PCP.cost_calculation_method   = 'R' AND RPH.RP_RECORD_ID = PCP.COST_RATEPROF_RECORD_ID  )
        OR ('&psRate_type' = 'All' AND  (   (RPH.RATE_TYPE = 'SEL' AND PCP.charge_calculation_method = 'R' AND RPH.RP_RECORD_ID = PCP.COST_RATEPROF_RECORD_ID)
                                         OR (RPH.RATE_TYPE = 'BUY' AND PCP.cost_calculation_method   = 'R' AND RPH.RP_RECORD_ID = PCP.COST_RATEPROF_RECORD_ID)))
      )