|The jOOQ User Manual. Multiple Pages : SQL building : Procedural statements : IF statement||previous : next|
All versions: 3.12 | Development versions: 3.13
Available in ❌ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
Conditional branching is an essential feature of all languages. Procedural languages support the
There are different styles of
IF statements in dialects, including:
- Requiring a
THENclause for the body of a branch, in case of which no BEGIN .. END block is required for multi-statement bodies.
- Allowing a dedicated
ELSIFclause for alternative, nested branches, to avoid nesting. This is mostly a syntax sugar feature only.
In jOOQ, an
IF statement might look as follows:
-- PL/SQL syntax IF i = 0 THEN INSERT INTO a (col) VALUES (1); ELSIF i = 1 THEN INSERT INTO b (col) VALUES (2); ELSE INSERT INTO c (col) VALUES (3); END IF;
// All dialects if_(i.eq(0)).then( insertInto(A).columns(A.COL).values(1) ).elsif(i.eq(1)).then( insertInto(B).columns(B.COL).values(2) ).else_( insertInto(C).columns(C.COL).values(3) )
Notice that both
else are reserved keywords in the Java language, so the jOOQ API cannot use them as method names. We've suffixed such conflicts with an underscore: