database - MySQL syntax checking if parameter is null -


i looking way execute mysql statement checking if given parameter exists. remember can following in oracle achieve that:

select s.* site s  s.study = :study , (:enabled null or s.enabled = :enabled) 

is possible in mysql too? same code executes without error never return records.

my goal here avoid multiple lfs , elses in java code. should work way query looks when enabled parameter null:

select s.* site s  s.study = :study 

and if parameter not null:

select s.* site s  s.study = :study , s.enabled = :enabled 

and want single query

i believe asking:

select s.* site s s.study = "some_study" , (s.enabled null or s.enabled = '' or s.enabled = "enabled"); 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -