Comments in SQL statements make applications easier to read and maintain. You can add comments between any keywords, parameters, or punctuation marks in a statement.
For example, you can use comments in statements to describe the purposes of these statements in applications. Comments that are not hints do not affect the execution of SQL statements.
You can add a comment to statements in the following ways:
Comments that start with a forward slash and asterisk (*)
Slashes and asterisks are used as delimiters to enclose a comment. The text can span multiple lines and must end with the delimiters */. The delimiters at the beginning and end of the comment do not need to be separated from the text by spaces or line breaks.
Comments that start with two hyphens (--).
The text following the symbol must be a comment, and a space must separate the symbol and comment. This text cannot span to a new line and ends with the line break character.
You can add multiple comments with two different styles in a single SQL statement. The text of each comment can contain any printable characters from the database character set.
The following example shows a comment that starts with a slash and an asterisk (/*).
SELECT last_name, emp_id, salary + NVL(comm_pct, 0),
job_id, e.dept_id
/* Select employees with a salary higher than Zhangsan's. */
FROM emp e, dept d
/*Data in the DEPT table contains the names of the departments.*/
WHERE e.dept_id = d.dept_id
AND salary + NVL(comm_pct,0) > /* Subquery: */
(SELECT salary + NVL(comm_pct,0)
FROM emp
WHERE last_name = 'Zhangsan')
ORDER BY last_name, emp_id;
The following example shows a comment that starts with two dashes ( -- ).
SELECT last_name, -- Select the name of the employee.
employee_id -- employee identifier
salary + NVL(commission_pct, 0), -- Total compensation
job_id, -- Job name
e.department_id -- Department
FROM employees e, -- Select from all employees.
departments d
WHERE e.department_id = d.department_id
AND salary + NVL(commission_pct, 0) >
(SELECT salary + NVL(commission_pct,0)
FROM employees
WHERE last_name = 'Zhangsan')
ORDER BY last_name
employee_id
;