Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CASE Statement in jooq?

I am new in jooq So i want to write this below query in jooq .

"CASE len(CAST(SUBSTRING(attachedblob, 1, 1) AS varchar(1))) when 1 then 'true' else 'false' end  ReviewExistance "

Can you tell me please .

Thanks

like image 990
user3062776 Avatar asked Feb 21 '26 05:02

user3062776


1 Answers

For completeness' sake, here's how your SQL expression could translate to jOOQ:

// Assuming a static import:
import static org.jooq.impl.DSL.*;
import static org.jooq.impl.SQLDataTypes.*;

decode().value(
       length(
           cast(
               substring(MY_TABLE.ATTACHEDBLOB, 1, 1),
               VARCHAR.length(1)
           )
       )
   )
   .when(1, "true")
   .otherwise("false")
   .as("ReviewExistance");

If that's too nasty, you can always resort to plain SQL. Examples are given here:

  • https://stackoverflow.com/a/19860383/521799
  • https://stackoverflow.com/a/20728037/521799
like image 78
Lukas Eder Avatar answered Feb 23 '26 20:02

Lukas Eder