Package org.jooq

Interface Declaration<T>

  • All Superinterfaces:
    QueryPart, java.io.Serializable, Statement

    @Pro
    public interface Declaration<T>
    extends Statement
    A local variable declaration.

    If your RDBMS supports procedural code, local variables can be used in procedural Block statements. In most RDBMS, such variables need to be declared first prior to using them.

    Example:

     // Assuming import static org.jooq.impl.DSL.*;
    
     Variable<Integer> i = var("i", SQLDataType.INTEGER);
     Variable<Integer> j = var("j", SQLDataType.INTEGER);
     using(configuration)
        .begin(
            declare(i),
            declare(j).set(1),
    
            i.set(j)
        )
        .execute();
     

    Just like in T-SQL (SQLDialect.SQLSERVER), local variables can be declared anywhere within a Block. If your RDBMS requires variables to be declared in a separate DECLARE clause of the block such as in PL/SQL (SQLDialect.ORACLE) and PL/pgSQL (SQLDialect.POSTGRES), then jOOQ will generate additional blocks and necessary DECLARE clauses to reflect the intended scoping of the jOOQ code. In order to get predictable results, however, it is recommended to explicitly declare variables at the beginning of a block.

    Instances can be created using DSL.declare(Variable) and overloads.

    Author:
    Lukas Eder