Oracle7 Server SQL Reference

Contents Index Home Previous Next

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:

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.

You can use comments in a SQL statement to pass instructions, or hints, to the Oracle7 optimizer. The optimizer uses these hints to choose an execution plan for the statement. For more information on hints, see the "Tuning SQL Statements" chapter of Oracle7 Server Tuning.

Note that you cannot use these styles of comments between SQL statements in a SQL script. You can use the Server Manager or SQL*Plus REMARK command for this purpose. For information on these commands, see Oracle Server Manager User's Guide or SQL*Plus User's Guide and Reference.

Example

These statements contain many comments:

SELECT ename, sal + NVL(comm, 0), job, loc
/* Select all employees whose compensation is
greater than that of Jones.*/
	FROM emp, dept
		 /*The DEPT table is used to get the department name.*/
	WHERE emp.deptno = dept.deptno
	  AND sal + NVL(comm,0) >	 /* Subquery:		   */
   (SELECT sal + NLV(comm,0)
   /* total compensation is sal + comm */
			FROM emp 
			WHERE ename = 'JONES')
SELECT ename,			-- select the name
		sal + NVL(comm, 0)		-- total compensation
		job				-- job
		loc				-- and city containing the office
	FROM emp,			-- of all employees
	     dept
	WHERE emp.deptno = dept.deptno
	  AND sal + NVL(comm, 0) >	-- whose compensation 
						-- is greater than
	    (SELECT sal + NVL(comm,0)	-- the compensation
		FROM emp 
		WHERE ename = 'JONES') 	-- of Jones.

Comments on Schema Objects

You can associate a comment with a table, view, snapshot, or column using the COMMENT command described[*], "Commands" of this manual. Comments associated with schema objects are stored in the data dictionary.


Contents Index Home Previous Next