Search code examples
sqloracle-databaseplsqloracle-apex-5

oracle add a condition inside where clause


I have a doubt how to insert a condition inside a where (on the picture you will see what i want to get).

enter image description here

It means, if my where receive a parameter , filter the result using that parameter on an specific column, if that parameter is null (it emans i don't send anything) show all records.

Is it possible to do it?

i start something but, i'm not really sure how to continue.

Can somebody help me?

select *
from objects o
where case when :COD is not null then (o.cod = :COD)
      --else --list all values
      end
;

Solution

  • I think you are looking for or:

    where (o.cod = :COD or :COD is null)
    

    This is almost exactly how you phrased the question, by the way.