Basic Elements of Oracle SQL 之 Comments



Basic Elements of Oracle SQL 之 Comments.

Comments
You can associate comments with SQL statements and schema objects.
Comments Within SQL Statements
Comments within SQL statements do not affect the statement execution, but they may make your application easier for you to read and maintain. You may want to include a comment in a statement that describes the statement’s purpose within your application.
A comment can appear between any keywords, parameters, or punctuation marks in a statement. You can include a comment in a statement using either of these means:
Begin the comment with a slash and an asterisk (/*). Proceed with the text of the comment. This text can span multiple lines. End the comment with an asterisk and a slash (*/). The opening and terminating characters need not be separated from the text by a space or a line break.
Begin the comment with — (two hyphens). Proceed with the text of the comment. This text cannot extend to a new line. End the comment with a line break.
A SQL statement can contain multiple comments of both styles. The text of a comment can contain any printable characters in your database character set.
Example
These statements contain many comments:
SELECT last_name, 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 salar + commission_pct */
FROM employees
WHERE last_name = ‘Pataballa’);

SELECT last_name, — select the name
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.
;
Comments on Schema Objects
You can associate a comment with a table, view, materialized view, or column using the COMMENT command. Comments associated with schema objects are stored in the data dictionary.