1
我需要一個過濾條件包含在一個選擇查詢當一個條件包裝在一個函數滿足。 如果條件不滿足,則不應應用過濾條件。CASE構造在哪裏條款
代碼:
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>>;
有什麼想法?
哼。 ..只是想着它!謝謝 ! – Casey