Conditional WHERE clause with CASE statement in Oracle

前端 未结 1 767
滥情空心
滥情空心 2020-12-10 01:11

I\'m brand-new to the Oracle world so this could be a softball. In working with an SSRS report, I\'m passing in a string of states to a view. The twist is that the users c

相关标签:
1条回答
  • 2020-12-10 01:46

    You can write the where clause as:

    where (case when (:stateCode = '') then (1)
                when (:stateCode != '') and (vw.state_cd in (:stateCode)) then 1
                else 0)
           end) = 1;
    

    Alternatively, remove the case entirely:

    where (:stateCode = '') or
          ((:stateCode != '') and vw.state_cd in (:stateCode));
    

    Or, even better:

    where (:stateCode = '') or vw.state_cd in (:stateCode)
    
    0 讨论(0)
提交回复
热议问题