I want to select rows using LIKE %:myParam% based on the query parameter ONLY if it is not null or empty. If the query parameter is null or empty, I want to select all records & drop the Like %%. How can I do that? I have tried with case-when but I am not sure How to use Like in it. Basically I want to use the like based on null check's result.
I have something like this:
Select * from myTable tbl
WHERE tbl.myCol LIKE '%' || :myParam|| '%'
For example: Select * from myTable returns 10 rows - from which 4 rows have myCol= null, I want to select 10 rows if :myParam is null/empty otherwise I want to get rows matching the LIKE expression. I dont want to get 6 rows if null is passed as :myParam
tbl.myCol LIKE '%' || nvl(:myParam,tbl.myCol) || '%'
– Jorge Campos