Oracle
 sql >> Database >  >> RDS >> Oracle

Clausola WHERE condizionale con istruzione CASE in Oracle

Puoi scrivere il where clausola come:

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

In alternativa, rimuovi il case interamente:

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

O, ancora meglio:

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