Db2 Formatter
Format IBM Db2 SQL for Db2 for LUW and Db2 for z/OS with Db2 rules for X'', G'' and N'' literals, double-quoted identifiers and names with #, @ and $. FETCH FIRST n ROWS ONLY gets its own line, isolation clauses such as WITH UR stay on the query line and MERGE branches start new lines. Unclosed strings and parentheses are reported with line and column for database developers and DBAs.
Frequently asked questions
Which Db2 syntax is understood?
Single-quoted strings with doubled quotes, hex X'', graphic G'' and national N'' literals as well as GX'', UX'' and BX'' strings are recognized. Double-quoted identifiers and ordinary names that contain #, @ or $ are kept intact.
How is FETCH FIRST handled?
FETCH starts its own line like LIMIT. The rest of the clause, such as FIRST 10 ROWS ONLY, stays together on the line below.
What about WITH UR and other isolation clauses?
WITH UR, WITH CS, WITH RS and WITH RR stay on the same line as the clause before them. They are never mistaken for a WITH common table expression.
Does it support MERGE?
Yes. WHEN MATCHED THEN and WHEN NOT MATCHED THEN branches start new lines.
Can it format SQL PL procedures?
Yes. BEGIN and END blocks with IF, CASE and LOOP constructs are indented, with statements inside on their own lines.
Are comments kept?
Yes. -- line comments and /* block comments */ stay in place. Multi-line block comments are re-indented to the new layout.
Does it change keyword case?
No. Keywords and names keep the case you wrote. Unquoted Db2 names are folded to upper case by the database anyway, so mixed case still works.
Which errors are detected?
Unclosed strings, quoted identifiers and block comments, and unbalanced parentheses, each with line and column. Nothing is sent to a database.
How large can the input be?
Up to 1 MB per request and 128 KB per statement. Long scripts are formatted one statement at a time.
Can I choose the indentation, and is my SQL stored?
Use 2 or 4 spaces or tabs. The SQL is formatted in memory only and never saved.