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. 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, employee_id, salary + NVL(commission_pct, 0),
job_id, e.department_id
/* Select all employees whose compensation is
greater than that of Pataballa.*/
FROM employees e, departments d
/*The DEPARTMENTS table is used to get the department name.*/
WHERE e.department_id = d.department_id
AND salary + NVL(commission_pct,0) > /* Subquery: */
(SELECT salary + NVL(commission_pct,0)
/* total compensation is salary + commission_pct */
FROM employees
WHERE last_name = 'Pataballa')
ORDER BY last_name, employee_id;
The following example shows a comment that starts with two hyphens (--).
SELECT last_name, -- select the name
employee_id -- employee id
salary + NVL(commission_pct, 0), -- total compensation
job_id, -- job
e.department_id -- and department
FROM employees e, -- of all employees
departments d
WHERE e.department_id = d.department_id
AND salary + NVL(commission_pct, 0) > -- whose compensation
-- is greater than
(SELECT salary + NVL(commission_pct,0) -- the compensation
FROM employees
WHERE last_name = 'Pataballa') -- of Pataballa
ORDER BY last_name -- and order by last name
employee_id -- and employee id.
;