How to format PL/SQL code
There is no official Oracle style, but a consistent one makes code reviews faster and diffs smaller. These conventions are common in Oracle teams.
Case and indentation
- One case for keywords, used everywhere: upper (SELECT) or lower (select). Mixing is what hurts.
- Indent blocks by a fixed step (2 or 4 spaces): the body of BEGIN, IF, LOOP and CASE.
- One clause per line in queries: SELECT, FROM, WHERE, GROUP BY, ORDER BY.
Lists and conditions
select o.order_id
, o.order_date
, c.name as customer_name
from orders o
join customers c on c.customer_id = o.customer_id
where o.status = 'OPEN'
and o.amount > 1000
order by o.order_date;Parameters and names
One parameter per line, with modes, types and defaults aligned, and prefixes that say what a name is: p_ for parameters, l_ for local variables, g_ for package globals, c_ for constants.
procedure add_order_line (
p_order_id in orders.order_id%type,
p_product_id in products.product_id%type,
p_quantity in number default 1,
p_line_id out order_lines.line_id%type
);Let a formatter keep it
Conventions only hold when a tool applies them. In Felix, Ctrl+Shift+F formats the window and Ctrl+Alt+F the statement, with rules for case, lists, commas and alignment, saved as profiles your team exports and shares. Formatting only changes spacing, line breaks and case, and comments stay where you wrote them.
More about it: SQL and PL/SQL formatter in Felix.
Try it on your own database
Felix is a Windows IDE for Oracle SQL and PL/SQL, from 11g to 23ai. Every feature is in the free 30-day trial; no account needed.