All versions: 3.11 | 3.10 | 3.9 | 3.8 | 3.7 | 3.6 | 3.5 | 3.4 | 3.3 | Development versions: 3.12 | Unsupported versions: 3.2 | 3.1 | 3.0 | 2.6

Sequences implement the org.jooq.Sequence interface, providing essentially this functionality:

// Get a field for the CURRVAL sequence property
Field<T> currval();

// Get a field for the NEXTVAL sequence property
Field<T> nextval();

So if you have a sequence like this in Oracle:

CREATE SEQUENCE s_author_id

You can then use your generated sequence object directly in a SQL statement as such:

// Reference the sequence in a SELECT statement:
Field<BigInteger> s = S_AUTHOR_ID.nextval();
BigInteger nextID = create.select(s).fetchOne(s);

// Reference the sequence in an INSERT statement:
create.insertInto(AUTHOR, AUTHOR.ID, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME)
      .values(S_AUTHOR_ID.nextval(), val("William"), val("Shakespeare"))
      .execute();
  • For more information about generated sequences, refer to the manual's section about generated sequences
  • For more information about executing standalone calls to sequences, refer to the manual's section about sequence execution
The jOOQ Logo