Skip Headers

Oracle® Database SQL Reference
10g Release 1 (10.1)

Part Number B10759-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Feedback

Go to previous page
Previous
Go to next page
Next
View PDF

Comments

You can associate comments with SQL statements and schema objects.

Comments Within SQL Statements

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.


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. Please refer to COMMENT for a description of comments.

Hints

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.


tablespec::=
Description of tablespec.gif follows
Description of the illustration tablespec.gif


indexspec::=
Description of indexspec.gif follows
Description of the illustration indexspec.gif

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 the tablespec and indexspec syntax

Table 2-22 Hints by Functional Category

Category Hint Name Link to Syntax
Optimization Goals and Approaches ALL_ROWS

FIRST_ROWS

all_rows_hint::=

first_rows_hint::=


RULE rule_hint::=
Access Path Hints CLUSTER cluster_hint::=
FULL full_hint::=
HASH hash_hint::=
INDEX

NO_INDEX

index_hint::=

no_index_hint::=


INDEX_ASC

INDEX_DESC

index_asc_hint::=

index_desc_hint::=


INDEX_COMBINE index_combine_hint::=
INDEX_JOIN index_join_hint::=
INDEX_FFS index_ffs_hint::=
INDEX_SS index_ss_hint::=
INDEX_SS_ASC index_ss_asc_hint::=
INDEX_SS_DESC index_ss_desc_hint::=
NO_INDEX_FSS no_index_ffs_hint::=
NO_INDEX_SS no_index_ss_hint::=
Join Order Hints ORDERED ordered_hint::=
LEADING leading_hint::=
Join Operation Hints USE_HASH

NO_USE_HASH

use_hash_hint::=

no_use_hash_hint::=


USE_MERGE

NO_USE_MERGE

use_merge_hint::=

no_use_merge_hint::=


USE_NL

USE_NL_WITH_INDEX

NO_USE_NL

use_nl_hint::=

use_nl_with_index_hint::=

no_use_nl_hint::=


Parallel Execution Hints PARALLEL

NO_PARALLEL

parallel_hint::=

no_parallel_hint::=


PARALLEL_INDEX

NO_PARALLEL_INDEX

parallel_index_hint::=

no_parallel_index_hint::=


PQ_DISTRIBUTE pq_distribute_hint::=
Query Transformation Hints FACT

NOFACT

fact_hint::=

no_fact_hint::=


MERGE

NO_MERGE

merge_hint::=

no_merge_hint::=


NO_EXPAND no_expand_hint::=
REWRITE

NO_REWRITE

rewrite_hint::=

no_rewrite_hint::=


UNNEST

NO_UNNEST

unnest_hint::=

no_unnest_hint::=


STAR_TRANSFORMATION

NO_STAR_TRANSFORMATION

star_transformation_hint::=

no_star_transformation_hint::=


NO_QUERY_TRANSFORAMTION no_query_transformation_hint::=
USE_CONCAT use_concat_hint::=
Other Hints APPEND

NOAPPEND

append_hint::=

noappend_hint::=


CACHE

NOCACHE

cache_hint::=

nocache_hint::=


CURSOR_SHARING_EXACT cursor_sharing_exact_hint::=
DRIVING_SITE driving_site_hint::=
DYNAMIC_SAMPLING dynamic_sampling_hint::=
PUSH_PRED

NO_PUSH_PRED

push_pred_hint::=

no_push_pred_hint::=


PUSH_SUBQ

NO_PUSH_SUBQ

push_subq_hint::=

no_push_subq_hint::=


QB_NAME qb_name::=
SPREAD_MIN_ANALYSIS spread_min_analysis_hint::=


all_rows_hint::=
Description of all_rows_hint.gif follows
Description of the illustration all_rows_hint.gif


append_hint::=
Description of append_hint.gif follows
Description of the illustration append_hint.gif


cache_hint::=
Description of cache_hint.gif follows
Description of the illustration cache_hint.gif


cluster_hint::=
Description of cluster_hint.gif follows
Description of the illustration cluster_hint.gif


cursor_sharing_exact_hint::=
Description of cursor_sharing_exact_hint.gif follows
Description of the illustration cursor_sharing_exact_hint.gif


driving_site_hint::=
Description of driving_site_hint.gif follows
Description of the illustration driving_site_hint.gif


dynamic_sampling_hint::=
Description of dynamic_sampling_hint.gif follows
Description of the illustration dynamic_sampling_hint.gif


fact_hint::=
Description of fact_hint.gif follows
Description of the illustration fact_hint.gif


first_rows_hint::=
Description of first_rows_hint.gif follows
Description of the illustration first_rows_hint.gif


full_hint::=
Description of full_hint.gif follows
Description of the illustration full_hint.gif


hash_hint::=
Description of hash_hint.gif follows
Description of the illustration hash_hint.gif


index_hint::=
Description of index_hint.gif follows
Description of the illustration index_hint.gif


index_asc_hint::=
Description of index_asc_hint.gif follows
Description of the illustration index_asc_hint.gif


index_combine_hint::=
Description of index_combine_hint.gif follows
Description of the illustration index_combine_hint.gif


index_desc_hint::=
Description of index_desc_hint.gif follows
Description of the illustration index_desc_hint.gif


index_ffs_hint::=
Description of index_ffs_hint.gif follows
Description of the illustration index_ffs_hint.gif


index_join_hint::=
Description of index_join_hint.gif follows
Description of the illustration index_join_hint.gif


index_ss_hint::=
Description of index_ss_hint.gif follows
Description of the illustration index_ss_hint.gif


index_ss_asc_hint::=
Description of index_ss_asc_hint.gif follows
Description of the illustration index_ss_asc_hint.gif


index_ss_desc_hint::=
Description of index_ss_desc_hint.gif follows
Description of the illustration index_ss_desc_hint.gif


leading_hint::=
Description of leading_hint.gif follows
Description of the illustration leading_hint.gif


merge_hint::=
Description of merge_hint.gif follows
Description of the illustration merge_hint.gif


noappend_hint::=
Description of noappend_hint.gif follows
Description of the illustration noappend_hint.gif


nocache_hint::=
Description of nocache_hint.gif follows
Description of the illustration nocache_hint.gif


no_expand_hint::=
Description of no_expand_hint.gif follows
Description of the illustration no_expand_hint.gif


no_fact_hint::=
Description of no_fact_hint.gif follows
Description of the illustration no_fact_hint.gif


no_index_hint::=
Description of no_index_hint.gif follows
Description of the illustration no_index_hint.gif


no_index_ffs_hint::=
Description of no_index_ffs_hint.gif follows
Description of the illustration no_index_ffs_hint.gif


no_index_ss_hint::=
Description of no_index_ss_hint.gif follows
Description of the illustration no_index_ss_hint.gif


no_merge_hint::=
Description of no_merge_hint.gif follows
Description of the illustration no_merge_hint.gif


no_parallel_hint::=
Description of no_parallel_hint.gif follows
Description of the illustration no_parallel_hint.gif


Restriction on NO_PARALLEL

You cannot parallelize a query involving a nested table.


no_parallel_index_hint::=
Description of no_parallel_index_hint.gif follows
Description of the illustration no_parallel_index_hint.gif


no_push_pred_hint::=
Description of no_push_pred_hint.gif follows
Description of the illustration no_push_pred_hint.gif


no_push_subq_hint::=
Description of no_push_subq_hint.gif follows
Description of the illustration no_push_subq_hint.gif


no_rewrite_hint::=
Description of no_rewrite_hint.gif follows
Description of the illustration no_rewrite_hint.gif


no_query_transformation_hint::=
Description of no_query_transformatn_hint.gif follows
Description of the illustration no_query_transformatn_hint.gif


no_star_transformation_hint::=
Description of no_star_transformation_hint.gif follows
Description of the illustration no_star_transformation_hint.gif


no_unnest_hint::=
Description of no_unnest_hint.gif follows
Description of the illustration no_unnest_hint.gif


no_use_hash_hint::=
Description of no_use_hash_hint.gif follows
Description of the illustration no_use_hash_hint.gif


no_use_merge_hint::=
Description of no_use_merge_hint.gif follows
Description of the illustration no_use_merge_hint.gif


no_use_nl_hint::=
Description of no_use_nl_hint.gif follows
Description of the illustration no_use_nl_hint.gif


ordered_hint::=
Description of ordered_hint.gif follows
Description of the illustration ordered_hint.gif


parallel_hint::=
Description of parallel_hint.gif follows
Description of the illustration parallel_hint.gif

Oracle ignores parallel hints on a temporary table. Please refer to CREATE TABLE and Oracle Database Concepts for more information on parallel execution.


parallel_index_hint::=
Description of parallel_index_hint.gif follows
Description of the illustration parallel_index_hint.gif


pq_distribute_hint::=
Description of pq_distribute_hint.gif follows
Description of the illustration pq_distribute_hint.gif


See Also:

Oracle Database Performance Tuning Guide for the permitted combinations of distributions for the outer and inner join tables


push_pred_hint::=
Description of push_pred_hint.gif follows
Description of the illustration push_pred_hint.gif


push_subq_hint::=
Description of push_subq_hint.gif follows
Description of the illustration push_subq_hint.gif


qb_name::=
Description of qb_name_hint.gif follows
Description of the illustration qb_name_hint.gif


rewrite_hint::=
Description of rewrite_hint.gif follows
Description of the illustration rewrite_hint.gif


rule_hint::=
Description of rule_hint.gif follows
Description of the illustration rule_hint.gif


spread_min_analysis_hint::=
Description of spread_min_analysis_hint.gif follows
Description of the illustration spread_min_analysis_hint.gif


star_transformation_hint::=
Description of star_transformation_hint.gif follows
Description of the illustration star_transformation_hint.gif


unnest_hint::=
Description of unnest_hint.gif follows
Description of the illustration unnest_hint.gif


use_concat_hint::=
Description of use_concat_hint.gif follows
Description of the illustration use_concat_hint.gif


use_hash_hint::=
Description of use_hash_hint.gif follows
Description of the illustration use_hash_hint.gif


use_merge_hint::=
Description of use_merge_hint.gif follows
Description of the illustration use_merge_hint.gif


use_nl_hint::=
Description of use_nl_hint.gif follows
Description of the illustration use_nl_hint.gif


use_nl_with_index_hint::=
Description of use_nl_with_index_hint.gif follows
Description of the illustration use_nl_with_index_hint.gif