Oracle PL/SQL - Single-Line Comments

Introduction

The PL/SQL compiler ignores comments. You can use comments to document your source code.

You can disable obsolete or unfinished pieces of code by turning them into comments.

A single-line comment begins with -- and extends to the end of the line.

The following code has three single-line comments.

Demo

SQL>
SQL> DECLARE-- from ww  w .  j  a  va 2s .c o  m
  2    howmany     NUMBER;
  3    num_tables  NUMBER;
  4  BEGIN
  5    -- Begin processing
  6    SELECT COUNT(*) INTO howmany
  7    FROM USER_OBJECTS
  8    WHERE OBJECT_TYPE = 'TABLE'; -- Check number of tables
  9
 10    DBMS_OUTPUT.PUT_LINE('howmany:' || TO_CHAR(howmany));
 11
 12    num_tables := howmany;       -- Compute another value
 13
 14    DBMS_OUTPUT.PUT_LINE('num_tables:' || TO_CHAR(num_tables));
 15
 16  END;
 17  /
howmany:963
num_tables:963

PL/SQL procedure successfully completed.

SQL>

In the following code, while testing or debugging a program, you can disable a line of code by making it a comment. For example:

-- DELETE FROM emp WHERE comm_pct IS NULL