当满足包装在函数中的条件时,我需要在选择查询中包含过滤条件。如果条件不满足,则不应应用过滤条件。
代码:
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>>;
有什么想法吗 ?