 |
|
ss
Oracle Tips by Burleson |
PL/SQL Code Comments
PL/SQL
supports two types of comments.
If the commend is only one line, you can use the double hyphen (--) to
mark a line as a comment. Multiple lines can be commented by
bracketing them with the slash star (/*…*/).
SQL> declare
2 v_line varchar2(40);
3 begin
4 -- this is a single line comment
5 v_line := 'Hello World';
6 dbms_output.put_line (v_line);
7 /* This is a
8 multiple line
9 comment
10 */
11 end;/
Hello World
It has become common to document the code by
adding comments that explain not only what the procedure
(function or block) does but also defines exactly what variables
are passed and how they are changed. This “self documented” code is
invaluable in assisting someone who has to later maintain the code.
Here is a good example.
SQL> declare
2 /* This anonymous block uses a SQL*Plus
3 variable as input, appends Hello to
4 the front and writes it out to the
5 buffer.
6
7 Requirements:
8 1. v_string must be defined before
execution
9 2. Must set serveroutput on to retrieve
10 results
11 */
12 v_line varchar2(40):= '&v_string';
13 begin
14 v_line := 'Hello '||v_line;
15 dbms_output.put_line (v_line);
16 end;
17 /
Enter value for v_string: Sammy
old 12:
v_line varchar2(40):= '&v_string';
new 12: v_line varchar2(40):= 'Sammy';
Hello Sammy
Next, let’s look at variable declaration and
manipulation.
The above book excerpt is from:
Easy Oracle PL/SQL Programming
Get Started
Fast with Working PL/SQL Code Examples
ISBN 0-9759135-7-3
John Garmany
http://www.rampant-books.com/book_2005_1_easy_plsql.htm
|