jOOQ and creating stored functions/procedures
Starting with version 3.15, jOOQ began to add an API for creating stored functions, procedures, and triggers. Among others, we have support for CREATE FUNCTION
, CREATE OR REPLACE FUNCTION
, CREATE PROCEDURE
, CREATE OR REPLACE PROCEDURE
, DROP FUNCTION
, and DROP PROCEDURE
.
Creating stored functions
For instance, creating a scalar function for MySQL can be done as follows:
Parameter<Integer> quantity = in("quantity", INTEGER); Parameter<Double> listPrice = in("list_price", DOUBLE); Parameter<Double> fractionOfPrice = in("fraction_of_price", DOUBLE); ctx.createOrReplaceFunction("sale_price_jooq") .parameters(quantity, listPrice, fractionOfPrice) .returns(DECIMAL(10, 2)) .deterministic() .as(return_(listPrice.minus(listPrice .mul(fractionOfPrice)).mul(quantity)))...