home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


2.5 Comments

Inline documentation, otherwise known as comments, is an important element of a good program. While this book offers many suggestions on how to make your program self-documenting through good naming practices and modularization, such techniques are seldom enough by themselves to guarantee a thorough understanding of a complex program.

PL/SQL offers two different styles for comments: single-line and multiline block comments.

2.5.1 Single-Line Comment Syntax

The single-line comment is initiated with two hyphens ( -- ), which cannot be separated by a space or any other characters. All text after the double hyphen, to the end of that physical line, is considered commentary and is ignored by the compiler. If the double hyphen appears at the beginning of the line, then that whole line is a comment.

Remember: the double hyphen comments out the remainder of a physical line, not a logical PL/SQL statement. In the following IF statement, I use a single-line comment to clarify the logic of the Boolean expression:

IF salary < min_salary (1994) -- Function returns min salary for year.
THEN
   salary := salary + salary*.25;
END IF;

2.5.2 Multiline Comment Syntax

While single-line comments are useful for documenting brief bits of code and also ignoring a line that you do not want executed at the moment, the multiline comment is superior for including longer blocks of commentary.

Multiline comments start with a slash-asterisk ( /* ) and end with an asterisk-slash ( */ ). PL/SQL considers all characters found between these two sequences of symbols to be part of the comment, and they are ignored by the compiler.

The following example of multiline comments shows a header section for a procedure. I use the double vertical bars in the left margin so that, as the eye moves down the left edge of the program, it can easily pick out the chunks of comments:

PROCEDURE calc_revenue (company_id IN NUMBER) IS
/*
|| Program: calc_revenue
|| Author: Steven Feuerstein
|| Change history:
||    9/23/94 - Start program
*/
BEGIN
   ...
END;

You can also use multiline comments to block out lines of code for testing purposes. In the following example, the additional clauses in the EXIT statement are ignored so that testing can concentrate on the a_delimiter function:

EXIT WHEN a_delimiter (next_char)
/*
             OR
          (was_a_delimiter AND NOT a_delimiter (next_char))
*/
;


Previous: 2.4 The Semicolon Delimiter Oracle PL/SQL Programming, 2nd Edition Next: 2.6 The PRAGMA Keyword
2.4 The Semicolon Delimiter Book Index 2.6 The PRAGMA Keyword

The Oracle Library Navigation

Copyright (c) 2000 O'Reilly & Associates. All rights reserved.

Library Home Oracle PL/SQL Programming, 2nd. Ed. Guide to Oracle 8i Features Oracle Built-in Packages Advanced PL/SQL Programming with Packages Oracle Web Applications Oracle PL/SQL Language Pocket Reference Oracle PL/SQL Built-ins Pocket Reference