SQL Formatter


Topic pages


The SQL Formatter reformats selected Oracle SQL text into a consistent, readable layout. Select the text you want to format (one or more complete statements), then choose Tools > Text/Format > Format SQL or use the Editor context menu: Format SQL, or press the assigned shortcut keys (Ctrl+K,E and Shift+Ctrl+K,E by default). Holding Shift lets you adjust SQL Format settings before the action.

The central design goal is to produce output that is more compact and more natural to read than most SQL formatters. Many tools expand every clause onto its own line regardless of length, resulting in statements that scroll endlessly for what is essentially a simple query. This formatter takes the opposite approach: short clauses, short column lists, short subqueries, and short complete statements are kept on a single line whenever they fit within a configurable width limit. Only the parts of a query that genuinely benefit from vertical expansion are broken across lines, so the overall output stays as concise as the SQL itself allows.


How formatting works

The formatter tokenises the selected text using the same lexer as the syntax highlighter, then applies indentation and line-break rules to reassemble the token stream into formatted output. The original text is replaced by the formatted result in a single undo step.

Each statement (terminated by ; or the SQL*Plus / separator) is processed independently. Blank lines between statements are preserved as a single blank separator.

Indentation depth per level is taken from the document’s Indent Spacing setting (Settings → Editor → Editing).


Statement layout

If a complete statement is short enough to fit on a single line it is kept on one line (controlled by Simple statement and its max length setting). Otherwise each major clause starts on its own line at the base indentation level.

Short statement kept on one line:

SELECT sysdate FROM dual;

Longer statement expanded:

SELECT employee_id, last_name, salary
FROM   employees
WHERE  department_id = 10;

Comments

The formatter handles two comment styles:

Style Behaviour
-- end-line comment Kept on the same line as the preceding token. After all formatting is complete, every end-line comment in the statement is aligned to the same column — one space after the widest line of code in the statement.
/* block comment */ Single-line block comments are treated like ordinary tokens. Multi-line block comments are re-indented to the current indent level; continuation lines are adjusted by the same delta so the internal structure of the comment is preserved.

Query hints such as SELECT --+PARALLEL(e,4) or SELECT /*+ FULL(e) */ are kept on the same line as SELECT and are excluded from end-line comment alignment.

Note: A statement that contains an end-line comment is never collapsed to a single line, even if it would otherwise be short enough.