Oracle® Database SQL Reference 10g Release 1 (10.1) Part Number B10759-01 |
|
|
View PDF |
You can associate comments with SQL statements and schema objects.
Comments can make your application easier for you to read and maintain. For example, you can include a comment in a statement that describes the purpose of the statement within your application. With the exception of hints, comments within SQL statements do not affect the statement execution. Please refer to "Hints " on using this particular form of comment.
A comment can appear between any keywords, parameters, or punctuation marks in a statement. You can include a comment in a statement in two ways:
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.
Some of the tools used to enter SQL have additional restrictions. For example, if you are using SQL*Plus, by default you cannot have a blank line inside a multiline comment. For more information, please refer to the documentation for the tool you use as an interface to the database.
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.
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. ;
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. Please refer to COMMENT for a description of comments.
You can use comments in a SQL statement to pass instructions, or hints, to the Oracle Database optimizer. The optimizer uses these hints as suggestions for choosing an execution plan for the statement.
A statement block can have only one comment containing hints, and that comment must follow the SELECT
, UPDATE
, INSERT
, or DELETE
keyword. The following syntax shows hints contained in both styles of comments that Oracle supports within a statement block.
{DELETE|INSERT|SELECT|UPDATE} /*+ hint [text] [hint[text]]... */
or
{DELETE|INSERT|SELECT|UPDATE} --+ hint [text] [hint[text]]...
where:
DELETE
, INSERT
, SELECT
, or UPDATE
is a DELETE
, INSERT
, SELECT
, or UPDATE
keyword that begins a statement block. Comments containing hints can appear only after these keywords.
+ is a plus sign that causes Oracle to interpret the comment as a list of hints. The plus sign must follow immediately after the comment delimiter (no space is permitted).
hint
is one of the hints discussed in this section. The space between the plus sign and the hint is optional. If the comment contains multiple hints, then separate the hints by at least one space.
text
is other commenting text that can be interspersed with the hints.
Oracle Database treats misspelled hints as regular comments and does not return an error.
Many hints can apply both to specific tables or indexes and more globally to tables within a view or to columns that are part of indexes. The syntactic elements tablespec
and indexspec
define these global hints. For information on when to use global hints and how Oracle interprets them, please refer to Oracle Database Performance Tuning Guide.
Table 2-22 lists the hints by functional category and contains cross-references to its syntax. (In HTML and PDF, the cross-references are hyperlinks.) An alphabetical listing of the hints, including syntax, follows the table.
See Also: Oracle Database Performance Tuning Guide for more information on using hints to optimize SQL statements and on detailed information about using thetablespec and indexspec syntax |
Table 2-22 Hints by Functional Category
You cannot parallelize a query involving a nested table.
Oracle ignores parallel hints on a temporary table. Please refer to CREATE TABLE and Oracle Database Concepts for more information on parallel execution.
See Also: Oracle Database Performance Tuning Guide for the permitted combinations of distributions for the outer and inner join tables |