案例说明缺少括号

时间:2018-06-21 15:55:16

标签: sql

在运行以下SQL时,出现错误:

  

缺少括号

SELECT DISTINCT
    RPH.transport_mode, PCP.air_export_ind, PCP.air_import_ind  
FROM
    RATE_PROFILE_HEADER RPH, PARTNER_CHARGE_PROFILE PCP
WHERE
    PCP.charge_code = RPH.Charge_code 
    AND PCP.charge_calculation_method = 'R'                     
    AND RPH.RP_RECORD_ID = PCP.CHARGE_RATEPROF_RECORD_ID 
    AND CASE '&psTransport_mode' 
           WHEN 'A' 
              THEN (DECODE(RPH.transport_mode, 'ALL', 'A', RPH.transport_mode) = 'A') AND (PCP.air_export_ind = 'Y' or PCP.air_import_ind = 'Y') 
           WHEN 'M' 
              THEN (DECODE(RPH.transport_mode, 'ALL', 'M', RPH.transport_mode) = 'M') AND (PCP.air_export_ind = 'Y' or PCP.air_import_ind = 'Y') 
           ELSE NULL
        END

我想在THEN子句的WHERE中传递多个条件。

我是否必须使用IF语句?

1 个答案:

答案 0 :(得分:2)

完全不使用CASE语句如何。似乎您只需要一个嵌套的条件:

Select 
    distinct 
    RPH.transport_mode,
    PCP.air_export_ind,
    PCP.air_import_ind  
from 
    RATE_PROFILE_HEADER RPH, 
    PARTNER_CHARGE_PROFILE PCP
where 
    PCP.charge_code = RPH.Charge_code 
AND PCP.charge_calculation_method = 'R'                     
AND RPH.RP_RECORD_ID = PCP.CHARGE_RATEPROF_RECORD_ID 
AND 
    (
        '&psTransport_mode' = 'A' AND ( Decode(RPH.transport_mode,'ALL','A',RPH.transport_mode) = 'A') AND (PCP.air_export_ind = 'Y' or PCP.air_import_ind = 'Y') 
    OR
        '&psTransport_mode' = 'M' AND ( Decode(RPH.transport_mode,'ALL','M',RPH.transport_mode) = 'M') AND (PCP.air_export_ind = 'Y' or PCP.air_import_ind = 'Y') 
    )