Skip to content

PL SQL Vertical Spacing Best Practices Standards

Tako Lee edited this page Feb 21, 2014 · 10 revisions

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>

Clone this wiki locally