The jOOQ User Manual. Multiple Pages : SQL building : Procedural statements : REPEAT statement | previous : next |
All versions: 3.12 | Development versions: 3.13
REPEAT statement
Available in ❌ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
WHILE's lesser known little sibling is REPEAT
, which works the same way as Java's do
statement. It is mostly not as useful as WHILE
, but can be, occasionally, when a loop must be iterated at least once.
An example:
-- MySQL syntax REPEAT INSERT INTO t (col) VALUES (i); SET i = i + 1; UNTIL i > 10 END REPEAT;
// All dialects Variable<Integer> i = var("i", INTEGER); repeat( insertInto(T).columns(T.COL).values(i), i.set(i.plus(1)) ).until(i.gt(10))
Only few dialects support REPEAT
. If it is not supported, we can easily emulate it using labels and the EXIT statement, e.g. in PL/SQL:
-- PL/SQL <<generated_alias_1>> LOOP INSERT INTO t (col) VALUES (i); i := i + 1; EXIT generate_alias_1 WHEN i > 10; END LOOP;