Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 E-mail Us
 Oracle Articles
New Oracle Articles

 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog

 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Oracle Support

 SQL Tuning

 Oracle UNIX
 Oracle Linux
 Remote s
 Remote plans
 Application Server

 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S


 Consulting Staff
 Consulting Prices
 Help Wanted!


 Oracle Posters
 Oracle Books

 Oracle Scripts

Don Burleson Blog 







PL/SQL Spacing Standards

Oracle Tips by Jonathan Ingram

PL/SQL Horizontal Spacing Best Practices Standards

You?ve probably heard of the obfuscated C contest, where the entrants attempt to cram as much code as possible onto a single line that does some type of work while remaining completely unreadable. If you have any experience maintaining code, you?ve probably seen more than a few pieces of code that have a good chance of winning a contest like this. The guidelines presented in this section are an attempt to guide you away from writing hard-to-read code.

?  One of the most important elements in creating readable code is the spacing placed around operators. Below shows common operators and keywords that need to be preceded and followed by a space when they are used in expressions.

Operators and keywords to be preceded and followed by a space in expressions.

























Often more than one of the operators and keywords shown in Table D.3 will be adjacent to each other inside an expression. In this instance, it is recommended that only one space lie between the two operators/identifiers. For example:


?  Spaces should precede and follow character (') literals.

  SELECT first_name || ' ' || middle_name || ' ' || last_name
  WHERE  ssn = 999999999;

?  Do not leave any blank spaces preceding or following the ** operator.

  nRaisedNum := nNum**nPower;

?  Do not leave blank spaces before or after the plus (+) and minus (-) signs when used as unary operators.

  nNumber := -nSecondNumber;
  nNumber := +nSecondNumber;

?  Do not use spaces between multiple parentheses or semicolons (;). Always precede the first opening parenthesis of a set with a space.

  AND (((x < 5) AND (y < 5))
  OR   ((x > 5) AND (y > 5)));

PL/SQL Vertical Spacing Best Practices Standards

Vertical spacing helps distance elements in the code from one another, reducing the visual clutter above and below statements. To create appropriate vertical spacing for your code, place a blank line in the locations described in the following list:

?  Before lines containing the keywords IF, ELSE, ELSIF, and EXCEPTION. If the line is preceded by a comment, place the blank line before the comment instead of before the line of text.

  -- If the student's grade point average meets the criteria for
  -- mandatory academic counseling, add the student's name and social
  -- security number to the list.
  IF (nRealGPA < 1.5) THEN
  -- We also want to consider students who are failing two or more
  -- classes, even if their GPA is above 1.5.
  ELSIF Has_Two_Fails (nForSSN => nSSN) THEN

?  Before any line containing the LOOP keyword. Do not place a blank line before source code containing the END LOOP keyword. (As with lines of code containing the IF keyword, keep the comments for a line of code with the comment by placing a blank line before the comment.)

  -- For each student returned by the query, add the student's social
  -- security number to the PL/SQL table.
  FOR Students_rec IN Students_cur LOOP

?  Before each exception after the first declared within the EXCEPTION section of a PL/SQL block.


?  Before and after the variable, constant, and type declarations for a PL/SQL block.

  PROCEDURE Update_Student_GPA (nSSN IN     number)
  END Update_Student_GPA;

?  Following the declaration of the procedure and its parameters.

  PROCEDURE Update_Student_GPA (nSSN IN     number)

?  Do not place an empty line before a line containing the END IF keyword. Do place blank lines after the last line of code containing the END IF keyword.

  IF (some expression) THEN
    IF (some expression) THEN
      IF (some expression) THEN
      END IF;
    END IF;

This is an excerpt from "High Performance Oracle Database Automation", by Jonathan Ingram and Donald K. Burleson, Series Editor.

If you like Oracle tuning, you might enjoy my book "Oracle Tuning: The Definitive Reference", with 950 pages of tuning tips and scripts. 

You can buy it direct from the publisher for 30%-off and get instant access to the code depot of Oracle tuning scripts.



Oracle Training at Sea
oracle dba poster

Follow us on Twitter 
Oracle performance tuning software 
Oracle Linux poster


Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.