The PL/SQL compiler ignores comments.
Adding comments to your program makes the code more readable.
Typically, we use comments to describe the purpose and use of each code segment.
We can disable pieces of code by turning them into comments.
A single-line comment begins with --
.
It can appear anywhere on a line.
It extends to the end of the line.
The following code shows how to add comments to code block.
DECLARE -- w w w . ja v a 2 s .com
n_count NUMBER;
num_tables NUMBER;
BEGIN
-- Begin processing
SELECT COUNT(*) INTO n_count
FROM USER_OBJECTS
WHERE OBJECT_TYPE = 'TABLE'; -- Check number of tables
num_tables := n_count; -- Compute some other value
DBMS_OUTPUT.PUT_LINE('num_tables: ' || num_tables);
END;
/
The code above generates the following result.
The following code shows how to disable a delete statement.
DECLARE
n_count NUMBER;
num_tables NUMBER;
BEGIN
-- DELETE FROM employees WHERE comm_pct IS NULL
END;
/
A multiline comments begins with /*
, ends with */
, and can span multiple lines.
We can use multiline comment delimiters to comment out sections of code.
DECLARE -- from ww w . j ava 2 s. c o m
n_pi NUMBER := 3.14;
n_radius NUMBER := 5;
n_area NUMBER;
BEGIN
/* this is a comment
this is a comment. */
n_area := n_pi * n_radius**2;
DBMS_OUTPUT.PUT_LINE('The n_area is: ' || TO_CHAR(n_area));
END;
/
The code above generates the following result.