Comments within SQL statements can make your application easier to read and maintain. A comment can be placed between any keywords, parameters, or punctuation marks in a statement.
For example, you can add a comment in a statement to describe the purpose of the statement in your application. Comments, except for hints, within SQL statements have no effect on the execution of the statement.
You can add a comment to a statement in one of the following ways:
Start the comment with a slash and an asterisk (/*).
Add the comment text after the slash and the asterisk. The text can span multiple lines and must end with an asterisk and a slash (*/). Spaces or line breakers are not required between the comment content and opening or closing characters.
Start the comment with two hyphens (--).
Add the comment text after the two hyphens and a space. The text cannot extend to a new line and must end with a line break.
An SQL statement can contain multiple comments in both styles. The comment text can contain any printable character in 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 whose salary is higher than that of Zhangsan.*/
FROM emp e, dept d
/* The dept table stores 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 -- employee ID,
salary + NVL(commission_pct, 0), -- total salary,
job_id, -- job title,
e.department_id -- department
FROM employees e, -- from the employees table.
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
;