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

Free Oracle Tips

HTML Text

 Home
 E-mail Us
 Oracle Articles



 Oracle Training
 Oracle News

 Oracle Forum
 Class Catalog


 Our Staff
 Our Prices
 Help Wanted!

 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 UNIX
 Oracle UNIX
 Linux
 Oracle Linux
 Monitoring
 Remote help

 Remote plans
 Remote
services
 Oracle C++
 Oracle Java
 Apache
 JDeveloper
 App Server

 Applications
 Oracle Forms
 Oracle Portal
 11i Upgrades
 SQL Server
 Oracle Concepts
 HTML-DB Tips
 Software Help

 Remote Help  
 Development  

 Implementation


 Financials Training
 Oracle 11i
 Oracle Apps 11i
 Oracle Workflow
 Oracle AR 11i Class
 Oracle AP 11i class
 Oracle GL 11i class
 Oracle HR 11i class
 Oracle FA 11i class
 11i Project Mgt
 11i procurement
 11i collections


 Oracle Posters
 Oracle Books

 Oracle Tuning Book
 Oracle RAC Book
 Oracle Security
 Easy Oracle Books
 Oracle Scripts
 SQL Server DBA
 SQL Design Patterns
 WISE
 Excel-DB   


 BC Oracle News


 Rednecks!
 Dress code
 Arabian Stallion

 Burleson Arabians
 Guide Horses
 Don Burleson Blog
 Golf & Travel


 Privacy Policy
 

 

 
 

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.

+

-

*

/

&

<

>

=

!=

<=

>=

:=

=>

||

..

:

<>

IN

OUT

AND

OR

NOT

NULL

 


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:

  IF (vMajor IS NOT NULL) THEN

  Spaces should precede and follow character (') literals.

  SELECT first_name || ' ' || middle_name || ' ' || last_name
         'student_name'
  FROM   STUDENTS
  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
   <statements>
 
  --
  -- 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
     <statements>
 
  ELSE
     <statements>
  END IF;

  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
     <statements>
  END LOOP;

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

  EXCEPTION
    WHEN NO_DATA_FOUND THEN
         <statements>
 
    WHEN TOO_MANY_ROWS THEN
         <statements>
 
    WHEN OTHERS THEN
         <statements>

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

  PROCEDURE Update_Student_GPA (nSSN IN     number)
  IS
 
    <declaration>
    <declaration>
 
  BEGIN
    <statements>;
  END Update_Student_GPA;

  Following the declaration of the procedure and its parameters.

  PROCEDURE Update_Student_GPA (nSSN IN     number)
 
  IS

  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
         <statements>
      END IF;
    END IF;
  END IF;
 
  <statements>

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.


Is your RAC database Healthy?

Get the experts at Burleson Consulting to conduct a two day RAC health check and ensure the health of your RAC database. 

Why guess?  Have your RAC database certified by experienced RAC experts.

 

 

 

 
 
 

Oracle performance tuning book

 

 

Oracle performance tuning software

 
Oracle performance tuning software
 
SearchOracle web site
 
Oracle performance Tuning 10g reference poster
 
Oracle performance tuning webcast
 
Oracle training in Linux commands
 
Oracle training Excel
 
Oracle training & performance tuning books
 

 

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


 

Copyright © 1996 -  2007 by Burleson Enterprises, Inc. All rights reserved.

Oracle® is the registered trademark of Oracle Corporation.


Hit Counter