Calling Procedures with Default Parameters using JDBC or jOOQ

Using jOOQ's code generator to call stored procedures is a popular reason to use jOOQ. For example, when you have a procedure like the following Oracle PL/SQL procedure: CREATE OR REPLACE PROCEDURE p ( p_i1 IN number, p_o1 OUT number, p_i2 IN varchar2, p_o2 OUT varchar2 ) IS BEGIN p_o1 := p_i1; p_o2 := p_i2; … Continue reading Calling Procedures with Default Parameters using JDBC or jOOQ

The Best Way to Call Stored Procedures from Java: With jOOQ

jOOQ is mainly known for its powerful type safe, embedded, dynamic SQL capabilities that are made available through code generation. However, a secondary use case of code generation is to use it for stored procedures (possibly exclusively for stored procedures). Stored procedures are powerful ways of moving complex data processing logic to the server. This … Continue reading The Best Way to Call Stored Procedures from Java: With jOOQ

Translating Stored Procedures Between Dialects

In the past years, we've invested a lot of effort into improving our procedural language capabilities in jOOQ. What started with a simple internal API to support the emulations of DDL clauses like these: -- Some dialect that supports this create table if not exists t (i varchar(10)); -- Db2 begin declare continue handler for … Continue reading Translating Stored Procedures Between Dialects

A Guide to SQL Naming Conventions

One of Java's big strengths, in my opinion, is the fact that most naming conventions have been established by the creators of the language. For example: Class names are in PascalCase Member names are in camelCase Constants are in SNAKE_CASE If someone does not adhere to these conventions, the resulting code quickly looks non-idiomatic. What … Continue reading A Guide to SQL Naming Conventions

Calling an Oracle Function with PL/SQL BOOLEAN Type from SQL

One of the most wanted features in the Oracle database is the BOOLEAN type. The SQL standard specified it a while ago, and RDBMS like PostgreSQL show how powerful it can be, e.g. when using the EVERY() aggregate function. Before you move on reading this article, note that starting with Oracle 23c, the standard BOOLEAN … Continue reading Calling an Oracle Function with PL/SQL BOOLEAN Type from SQL

Beware of Hidden PL/SQL to SQL Context Switches

I recently stumbled upon a curious query on a customer's productive Oracle database: SELECT USER FROM SYS.DUAL Two things caught my attention: The query was executed many billions of times per month, accounting for about 0.3% of that system's load. That's 0.3% for something extremely silly! I don't think that customer would ever qualify the … Continue reading Beware of Hidden PL/SQL to SQL Context Switches

How to Run a Bulk INSERT .. RETURNING Statement With Oracle and JDBC

When inserting records into SQL databases, we often want to fetch back generated IDs and possibly other trigger, sequence, or default generated values. Let's assume we have the following table: -- DB2 CREATE TABLE x ( i INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, j VARCHAR(50), k DATE DEFAULT CURRENT_DATE ); -- PostgreSQL CREATE TABLE … Continue reading How to Run a Bulk INSERT .. RETURNING Statement With Oracle and JDBC

The Cost of JDBC Server Roundtrips

Or: Move That Loop into the Server Already! This article will illustrate the significance of something that I always thought to be common sense, but I keep seeing people getting this (very) wrong in their productive systems. Chances are, in fact, that most applications out there suffer from this performance problem - and the fix … Continue reading The Cost of JDBC Server Roundtrips

Impress Your Coworkers With the Incredible NATURAL FULL OUTER JOIN!

There are already only very few real-world use-cases for FULL [ OUTER ] JOIN, but maybe, you have run into this beast in the past. But when was the last time you've seen a NATURAL JOIN? Right. A quick reminder from our article about JOINs: FULL JOIN A FULL JOIN is a type of OUTER … Continue reading Impress Your Coworkers With the Incredible NATURAL FULL OUTER JOIN!

Use jOOQ to Read / Write Oracle PL/SQL RECORD Types

Some of the biggest limitations when working with Oracle PL/SQL from Java is the lack of support for a variety of PL/SQL features through the JDBC interface. This lack of support is actually not limited to JDBC, but also extends to Oracle SQL. For instance, if you're using the useful PL/SQL BOOLEAN type as such: … Continue reading Use jOOQ to Read / Write Oracle PL/SQL RECORD Types