You can comments to any SQL statements or any schema objects.
A)Comments Within SQL Statements
----------------------------------------
Comments within SQL statements do not affect the statement execution. The only exception is use of hints. With use hints the SQL statements is affected. In fact comment is used to make your application easier for you to read and maintain.
Within SQL statements you can include comment in two ways.
1)With /* and */
--------------------------
Format is,
Begin with slash (/) and an asterisk (*) together (/*) + comment Text + End with an asetrisk (*) and a slash (/) together (*/).
With this format text can span multiple lines.
The opening and terminating characters need not be separated from the text by a space or a line break.
Example:
-----------
SQL> select second_col /*This is column
2 Name */ from test /*This is Table Name*/ ;
2)with --
-----------------
The text that begin with two hyphens (--) is considered as comments. The comments written in this way can't span multiple lines. End the comment with a line break.
Example:
------------
SQL> select second_col -- THIS IS COMMENT
2 FROM TEST;
B)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.
You can view the comments on a particular table or column by querying the data dictionary views USER_TAB_COMMENTS, DBA_TAB_COMMENTS, or ALL_TAB_COMMENTS or USER_COL_COMMENTS, DBA_COL_COMMENTS, or ALL_COL_COMMENTS.
You can view the comments on a particular operator by querying the data dictionary views USER_OPERATOR_COMMENTS, DBA_OPERATOR_COMMENTS, or ALL_OPERATOR_COMMENTS.
You can view the comments on a particular indextype by querying the data dictionary views USER_INDEXTYPE_COMMENTS, DBA_INDEXTYPE_COMMENTS, or ALL_INDEXTYPE_COMMENTS.
You can view the comments on a particular materialized view by querying the data dictionary views USER_MVIEW_COMMENTS, DBA_MVIEW_COMMENTS, or ALL_MVIEW_COMMENTS.
To drop a comment from the database, set it to the empty string ' '.
Example:
--------------
I have comment on table test and on its columns by,
SQL> COMMENT ON TABLE ARJU.TEST IS 'This is test Table';
Comment created.
SQL> COMMENT ON COLUMN ARJU.TEST.SECOND_COL IS 'This is the only one column';
Comment created.
SQL> column COMMENTS format a30
SQL> col owner format a10
SQL> col table_name format a10
SQL> select OWNER,TABLE_NAME,COMMENTS from dba_tab_comments where table_name='TEST' and owner='ARJU';
OWNER TABLE_NAME COMMENTS
---------- ---------- ------------------------------
ARJU TEST This is test Table
SQL> select OWNER,TABLE_NAME,COMMENTS from dba_col_comments where table_name='TEST' and owner='ARJU';
OWNER TABLE_NAME COMMENTS
---------- ---------- ------------------------------
ARJU TEST This is the only one column
To drop comment,
SQL> COMMENT ON COLUMN ARJU.TEST.SECOND_COL IS '';
Comment created.
SQL> select OWNER,TABLE_NAME,COMMENTS from dba_col_comments where table_name='TEST' and owner='ARJU';
OWNER TABLE_NAME COMMENTS
---------- ---------- ------------------------------
ARJU TEST
Tuesday, June 10, 2008
Subscribe to:
Post Comments (Atom)
Tag Cloud
10.2g
10g
11g
11gR2
Abasa
About Oracle
Administration
Adsense
Alerts
Archival
ASM
ASP.Net
Audit
Audit Vault
Backup
Bangladesh
Block Corruption
Blogger
Browser
Bug
Business
Clone
Clusterware
Comments
Concepts
Connection
Controlfiles
Crime
CSS
Data Block
Data Dictionary
Data Guard
Data Mining
Data Pump
Data Type
Database Administration
Database Vault
DBConsole
Developer
Economics
EM
Excel
Exercise
Explain plan
Export
External Table
Facebook
Firefox
Firmware
Flashback
Forum
Functions
Games
Globalization Support
Grid Control
Hardware
History
HTML
IE
Import
Indexes
initializaion parameter
initialization parameter
Installation
Internals
Internet
Interview
isql*plus
Java
JavaScript
Job
Joins
Joke
Limitation
Linux
Listener
Logminer
Magento
Mail
Materialized View
Medical
Memory
Mobile
Money
Multimedia
MySQL
Net Services
Network
OCP
Operators
Oracle
Oracle Concepts
Oracle Recovery
OS
Others
OUI
Package
Packages
Parameters
Partitioning
Patchset
Performance
Perl
Pfile
Photos
PHP
PL/SQL
Profile
Pseudocolumns
Puzzle
Quiz
Quota
RAC
RAC Installation
Recovery
Recovery Problems
Redo Log
Reports
RMAN
Scripts
Security
SEO
Server Administration
SGA
Shell Script
Smarty
Social Marketing
Solaris
Spfile
SQL
SQL Tuning
SQL*Loader
Sql*Plus
Startup Problem
Streams
SwingBench
System Analysis
Tablespaces
Technology
Temp
TNS Error
Tools
Troubleshooting
Tuning
Undo
UNIX
Upgradation
Utilities
Version
Views
Vmware
Windows
Wordpress
XML
No comments:
Post a Comment