I am looking for the way to execute MySQL statement checking if given parameter exists. As I remember I can do the following in Oracle to achieve that:
select s.* from Site s
where s.study = :study
and (:enabled is null or s.enabled = :enabled)
is anything like that possible in MySQL too? The same code executes without error but never return any records.
My goal here is to avoid multiple lfs and elses in my java code. It should work the way that the query looks like that when enabled parameter is null:
select s.* from Site s
where s.study = :study
and like that if the parameter is not null:
select s.* from Site s
where s.study = :study
and s.enabled = :enabled
and I want to do that with a single query
解决方案
Unfortunately it is highly dependent on database driver. My initial query works when run in database tools but doesn't have to when it comes to run it by JPA. So I'm to close this question as it doesn't require further answers. I'm sorry lads for wasting your time.