You can add comments to SQL statements for easier reading and maintenance. These comments can be located anywhere in the SQL statement, such as between any keywords, parameters, or punctuation marks.
For example, you can add a comment to a SQL statement to describe its purpose in your application. In addition to hints, comments in a SQL statement do not affect the execution of the statement.
You can add a comment to a statement by using one of the following methods:
Comments that start with a slash and an asterisk (/*).
Comments that start with a forward slash ( /) and an asterisk ( *). The comment text can span multiple lines and ends with an asterisk followed by a forward slash ( */). The text does not have to be separated from the forward slash and asterisk by a space or a newline.
Comments that begin with two hyphens (--).
Text that follows a symbol in the comment must be preceded by a space. This text cannot be on a new line, and a line break must follow the text.
SQL statements can contain multiple comments of both styles. The text of comments can contain any printable character in the database character set.
The following examples show comments that start with a forward 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 contains 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 dashes ( - - ).
SELECT last_name, -- Select the employee name.
employee_id -- employee id
salary + NVL(commission_pct, 0), -- Total salary
job_id, -- Job ID
e.department_id -- Department
FROM employees e, -- Select 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
;