 |
|
PL/SQL Indentation Standards
Oracle Tips by Jonathan Ingram
|
PL/SQL Indentation Best Practices
Standards
The most important element in readable code is consistent indentation, which
illustrates clearly the logic flow of a procedure. Consider these blocks of
code:
IF (x < 7) THEN
IF (y < 0) THEN
<statements>
END IF;
ELSIF (x > 10) THEN
<statements>
ELSE
<statements>
END IF;
IF (x < 7) THEN
IF (y < 0) THEN
<statements>
END IF;
ELSIF (x > 10) THEN
<statements>
ELSE
<statements>
END IF;
Horizontal alignment in the second block of code makes it much easier to
follow, even though it is syntactically and functionally identical to the first
block of code.
You should not use more than three or four levels of indentation in any block
of code. If this many levels of indentation become necessary, consider breaking
the code into smaller modules. Too many levels of indentation is almost as bad
as no indentation at all.
? Code should always be
indented consistently, using three spaces for each level of indentation.
Variable, type, and constant declarations should all be indented to the first
level of indentation. Do not use tab characters.
IF (some expression) THEN
IF (some expression) THEN
IF (some expression) THEN
<statements>
ELSIF (some expression) THEN
<statements>
END IF;
END IF;
END IF;
<statements>
? Statements following
the WHEN clause of an exception handler should be indented five spaces,
in order to create a column-like effect within the exception handler.
Correct:
EXCEPTION
WHEN OTHERS THEN
DBMS_Output.Put_Line (SQLERRM);
Incorrect:
EXCEPTION
WHEN OTHERS THEN
DBMS_Output.Put_Line (SQLERRM);
This is an excerpt from "High Performance Oracle Database
Automation", by Jonathan Ingram and Donald K. Burleson, Series Editor.