Skip to content

PL SQL Vertical Spacing Best Practices Standards

shenhuan2021 edited this page Mar 3, 2024 · 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.

Delphi

  • gfmtopt.InsertBlankLineInBatchSqls, type of boolean

Java

  • public Boolean insertBlankLineInBatchSqls, type of boolean

Uniform

  • 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.

    Option: fmt112_vs_plsql_blank_line_before_if = true, type: TFmtBoolean.

    Option: fmt113_vs_plsql_blank_line_before_else = true, type: TFmtBoolean.

    Option: fmt114_vs_plsql_blank_line_before_elseif = true, type: TFmtBoolean.

    --
    -- 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.)

    Option: fmt116_vs_plsql_blank_line_before_loop = true, type: TFmtBoolean.

    --
    -- 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.

    Option: fmt117_vs_plsql_blank_line_before_each_exception_after_first = true, type: TFmtBoolean.

    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.

    Option: fmt118_vs_plsql_blank_line_before_variable_declaration = true, type: TFmtBoolean.

    Option: fmt119_vs_plsql_blank_line_after_variable_declaration = true, type: TFmtBoolean.

    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

    Option: fmt120_vs_plsql_blank_line_after_procedure_parameter_declaration = true, type: TFmtBoolean.

    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>

Reference: http://www.dba-oracle.com/t_plsql_coding_spacing_standards.htm

Clone this wiki locally