You can use comments in SQL statements to improve their readability and maintainability. A comment can be placed between any keyword, parameter, or punctuation mark in a statement.
For example, you can add comments in an SQL statement to describe the purpose of the statement in an application. Notes in an SQL statement do not affect the execution of the statement.
You can add comments to statements by using the following methods:
Comments starting with the / and * characters.
Slashes and asterisks are followed by text comments. This text can span multiple lines and ends with an asterisk and a slash (*/) to close the comment. The opening and closing symbols do not need to be separated from the text by spaces or line breaks.
Comments that begin with two hyphens (--)
The comment that follows the identifier must be preceded by a space, and it cannot be split across lines and must end with a line break.
A SQL statement can contain multiple comments of different types. The text of comments can contain any printable character from the database character set.
The following examples show a comment that begins with a slash and asterisk (*).
SELECT last_name, emp_id, salary + NVL(comm_pct, 0),
job_id, e.dept_id
SELECT * FROM employees WHERE salary > (SELECT salary FROM employees WHERE name='Zhangsan');
FROM emp e, dept d
/*The data in the DEPT table is department names.*/
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 hyphens (--).
SELECT last_name, -- Select the employee name.
employee_id -- ID of the employee
salary + NVL(commission_pct, 0), -- Total salary
job_id, -- The job name.
e.department_id -- Department
FROM employees e, -- Select 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
;