1

当满足包装在函数中的条件时,我需要在选择查询中包含过滤条件。如果条件不满足,则不应应用过滤条件。

代码:

select col_a,col_b,cancel_Date from tab_a 
where col_c = <<some_condition>>  
and (case when oracle_function() = 'YES' then 'tab_a.cancel_date is null'
      else null
    )

如果我这样写,那么它会抛出“无效的关系运算符”错误。意识到这种情况应该解决右边的一个值,我尝试添加这样的东西,当条件满足时,它不会给我预期的结果:

select col_a,col_b,cancel_Date from tab_a 
where col_c = <<some_condition>>  
and (case when oracle_function() = 'YES' then 'tab_a.cancel_date is null'
       else '1'
      ) = '1'

我的预期输出应该是:

如果 oracle_function() = YES,那么我的查询应该有效地解析为:

select col_a,col_b,cancel_Date from tab_a 
where col_c = <<some_condition>> and tab_a.cancel_date is null;

别的:

select col_a,col_b,cancel_Date from tab_a 
where col_c = <<some_condition>>;

有什么想法吗 ?

4

1 回答 1

2

代替case语句,此查询要求函数返回除 之外的值'YES',或者日期为空......这应该类似于您的原始查询:

select col_a,col_b,cancel_Date 
from tab_a 
where col_c = <<some_condition>>  
and (oracle_function() <> 'YES' OR tab_a.cancel_date is null)
于 2012-11-20T20:32:45.163 回答