Oracle SQL Quick Reference 6.0 - Quick Hand Guide
Oracle SQL Quick Reference 6.0 - Quick Hand Guide
UPDATE [user.] {tablelview) [alias] Redefines storage al1oeations for an existing rollback_segment, or makes
SET column = expr [, column = expr]
a prívate rollback_segment PUBLICo
[WHERE condition] ALTER SEQUENCE [user.]sequence
or [INCREMENT BY integer]
[MAXVALOE in t ege r I NOMAXVALOE]
UPDATE [user.]{tablelview} [alias]
[MINVALOE integerlNOMINVALOE]
SET (column [,column] ... ) = (subquery)
[CYCLE 1NOCYCLE]
[WHERE condition]
[CACHE integerlNOCACHE]
Changes the values of columns in rows that meet the WHERE condition [ORDER I NOORDER]
in a table or víew. Changes alJ rows if no WHERE condition is specified.
Redefines an existing sequence.
ALTER SESSION SET SQL_TRACE {TRUEIFALSE} AUDIT {optíon [,optíon] ... IALL}
Enables and di sables the SQL trace facility for the current user session. ON {[user.] {tablelvíewlsequencelsynonym} IDEFAULT}
[BY {SESSIONIACCESS}]
For information on the SQL trace facility, refer to the ORACLE RDBM5
[WHENEVER [NOT] SUCCESSFUL]
Performance Tuning Cuide, Part No. 531?-V6.0.
Enables auditing of access to a lable, view, sequence, or synonym based
ALTER TABLE [user.]table on the oplions. Enables default auditing of al! subsequently created
[ADD ({column_elementltable_constraint) tables if the DEFAULT option is specified.
[, {column_element I table_constraint}] )]
The oplions may include ALTER, AUDIT, COMMENT, DELETE,
[MODIFY (column_element [, column_element] )]
GRANT, INDEX, INSERT, LOCK, RENAME, SELECT, or UPDATE,
[DROP CONSTRAINT constraintj
depending on the types of objects.
[PCTFREE integer] [PCTUSED integer]
[INITRANS integer] [MAXTRANS ínteger] COMMENT ON {TABLE [user.] {tablelvíew}
[STORAGE storage] ICOLUMN [user.] {tablel view} .column}
[BACKUP] IS char
Redefines the columns, constraints, or storage alIocations of an existing Adds a comment about a table, view, or column to the Data Dictionary.
lable. Also records in the Data Dictionary that a table has been backed up. CREATE CLUSTER cluster
ALTER TABLESPACE tablespace (column datatype [,column datatype] ... )
(ADD DATAFILE filespec [REUSE] [PCTUSED 401 ínteger] [PCTFREE 101 ínteger]
[, fílespec [REUSE]] [SIZE ínteger]
IRENAME DATAFlLE 'fílename' [,' filename'] [INITRANS 1.1 ínteger] [MAXTRANS 2551 ínteger]
TO ' fílename' [,' fílename' ] [TABLESPACE tablespace]
I DEFAULT STORAGE storage [STORAGE storage]
IONLINE Creates a new cluster and specifies its cluster key columns.
IOFFLINE [NORMAL I IMMEDIATE]
CREATE DATABASE database
I {BEGIN IEND} BACKUP}
[CONTROLFILE REUSE]
Redefines an existing tablespace by: [LOGFlLE fílespec [, fílespec] ... J
· adding or renaming a database file [MAXLOGFILES ínteger]
· redefining default storage al1ocations [DATAFILE fílespec [, fílespec] ... ]
AIso changes the state of a lablespace by: [MAXDATAFILES ínteger]
[MAXINSTANCES ínteger]
moving the tablespace ONLINE or OFFLINE
· signifying that a backup of the database files has begun or completed [ARCHlVELOGINOARCHIVELOG]
[EXCLUSIVE]
ALTER USER user [IDENTIFIED BY password]
[DEFAULT TABLESPACE tablespace]
Creates a new database and:
[TEMPORARY TABLESPACE tablespace] sets maximum numbers of instances, database mes, and redo log files
specifies database files and redo log files
Changes the password, default tablespace, or temporarylablespace of an chooses mode for the redo log
existing user.
filespec is a file specification in this form:
AUDIT {system_opticn [,system optíon] I ALL}
[WHENEVER [NOT] SUCCESSFUL] , fílename' ¡SIZE ínteger [KIM]] [REUSE)
Enables auditing of database access based on the syslem_oplions. CREATE [PUBLIC] DATABASE LINK link
The system_options include CONNECT, DBA, NOT EXISTS, and [CONNECT TO user IDENTIFIED BY password]
RESOURCE. USING ' connect_stríng'
Creates a link from the local database to a user on a remote database
specified by a connecl_string. For information on specifying a remote
database, refer to the manual for your specific SQL*Net protocol.
CREATE [UNIQUE] INDEX index CREATE TABLE (continued)
ON {tab1e (co1umn (~IDESC)
column_element defines a column and has the form:
[, co1umn (MQIDESC)] ... )
ICLUSTER cluster} co1umn datatype [DEFAULT expr] [column_constraint]
[INITRANS integer] [MAXTRANS integer] where:
[TABLESPACE tab1espace]
[STORAGE storage] col umn is the column name.
[PCTFREE {lO I integer}] datatype is one ofthese datatypes:
[NOSORT] CHAR(size) or Variable length character string of up to size
Creates a new index on the specified columns in a table 01' cluster. CHARACTER (si characters. size defaults to 1. Maximum size
ze)
tableJonstraintrestricts the range of valid values for one or more Removes a tablespace from the database. Also removes all database
columns in the table. For more information on table constraints, refer objeets, sueh as tables and views, in the tablespace if you specify the
to the SQL Language Reference Manual, Part No. 778-V6.O. INCLUDING CONTENT5 option.
storage specifies storage allocation for a table, cluster, index, rollback DROP VIEW [user.]view
segment, or tablespace. storage has this form: Removes a view from the database.
( [INITIAL 10240 I integer] [NEXT 10240 I integer]
GRANT database_priv [, database_priv]
[MINEXTENTS 1.1 integer] [MAXEXTENTS 991 inceger] TO user [, user]
[PCTINCREASE 50 I integer] ) [IDENTIFIED BY password [, password] ... ]
Por more inforrnation on the storage clause and parameters, refer to Gives database privileges to a user.
the SQL Language Reference Manual, Part No. 778-V6.O. Oatabase privileges include OBA, CONNECT, and RESOURCE.
CREATE TABLESPACE tablespace GRANT RESO'ORCE [(quota [KIM])]
DATAFILE filespee [,fi1espee] ON tablespaee
[DEFAULT STORAGE storage] TO {PUBLIC I user [, user] ... }
[ONLINEIOFFLINE]
Gives a user access to a tablespace. Gives all users access to a tablespace
Creates a new tablespace and specifies: if PUBLlC is specified. Can also impose a quota on the space the user
the database files can use .
• the default storage allocations
. whether the tablespace is initial!y ONLlNE or OFFLINE GRANT {objeet_pri v [, objeet pri v] ... IALL [PRIVILEGES]}
ON (user.) {tablelviewlsequeneelsynonym}
CREATE VIEW [user.] view [(e_alias [, e~alias] ... )]
TO {userIPUBLIC} [, user]
AS query
[WITH GRANT OPTION]
[WITH CHECK OPTION [CONSTRAINT eonstraint]]
Gives a user object privileges on a table, view, sequence, or synonym.
Creates a new view. Gives al! users objeet privileges if PUBLICis specified. Allows a user
DROP CLUSTER [user.]eluster [INCLUDING TABLES] to subsequently give another user object privileges if the WITH
Removes a cluster from the database. Also removes tables in the cluster GRANT OPTION is specified.
if you specify the INCLUDING TABLE5option. Object privileges may include ALTER, OELETE,INOEX, IN5ERT,
REFERENCES,SELECT,or UPDATE, depending on the type of object.
DROP [PUBLIC] DATABASE LINK link
Removes a link to a remote databa se. LOCK TABLE [user.]table [, [user.]table]
IN (ROW SHARE
Removing a PUELlC database link requires OBA privilege.
IROW EXCLUSIVE
DROP INDEX [user.]index 1 SHARE UPDATE
Removes an index from the database. ISHARE
I SHARE ROW EXCLUSlVE
DROP [PUBLIC) ROLLBACK SEGMENT rollbaek_segment
IEXCLUSlVE) MODE
Removes a rollback_segment from the database. [NOWAIT]
DROP SEQUENCE [user.]sequenee Overrides default lock mode and reserves access to a table for the
Removes a sequence from the databa se. eurrent transaction. Perrnits or restricts aceess by other users,
depending upon the specified lock mode.
DROP [PUBLIC] SYNONYM [user.]synonym
For information on lock modes, refer to the ORACLE RDBMS Database
Removes a synonym from the databa se.
Administrator'sCuide, Part No. 3601-V6.O.
Removing a PUELlC synonym requires DBA privilege.
NOAUDIT {system_option [, system_option] ... IALL}
DROP TABLE [user.]cable [WHENEVER [NOT] SUCCESSFUL]
Removes a table from the database. Oisables auditing of database aceess based on the system_options.
NOAUDIT {option [,option] ... IALL} Operators
ON {tablelviewlsequencelsynonymIDEFAULT)
[WHENEVER (NOT) SUCCESSFUL] These tables list operators in descending order of precedence. In these tables,
Disables auditing of a table, view, sequence, or synonym based on the dotted lines separate operators of different precedence. When evaluating an
options. Disables default auditing of subsequently created tables if the expression, ORACLE evaluates operators with greater precedence first.
DEFAULT option is specified. Note: Parentheses O override normal precedence. ORACLE evaluates
RENAME old TO new operators inside parentheses before those outside.
Renames a table, view, or synonym fram old to new.
REVOKE database_pri v [,database_pri v] Arithmetic Operators
FROM user [,user] Operator
Revokes database privileges fram a user.
Database privileges include CONNECf, RESOURCE, and DBA. + .~..<()f\~op~r~.f\~) I?~n()t~s.~. p()s.it.i~~.()~11~~ati\,~ .~~p~~ssi()f\: ..
REVOKE RESOURCE
ON tablespace
FROM user [,user]
Revokes access to a tablespace fram a user.
REVOKE {object_pri v [,object_pri v] ... IALL [PRIVlLEGES]} Character Operators
ON [user.] {tablelviewlsequencelsynonym)
FROM {userIPUBLIC} [, user] Operator
Revokes object privileges on a table, view, sequence, or synonym from a user.
SET TRANSACTION READ ONLY
Enforces read consistency at the transaction leve!. Must be the first Comparison Operators
statement in the transaetion.
VALIDATE INDEX index
Operator
Checks the integrity of an index. Tests for equality.
!= 1\= <> Tests for inequality.
> >= < <= Greater than, greater than or equal to, less
than, less than or equal to.
You can use the ORACLE Precompilers to embed SQL statements into
Equal to any member of a set or subquery.
an application programo For the syntax of embedded SQL statements,
refer to the 5QL Language Reference Manual, Part No. 778-V6.0. AIso equivalent to '= ANY'.
Not equal to any member of a set or subquery.
Also equivalent to '!= ALL'.
Compares a value to each value returned by a
/* ... */ (Comment) list or subquery.
Comments may appear anywhere within a SQL statement. Compares a value to every value returned by a
EXPLAIN PLAN (SET
STATEMENT_ID = charJ list or subquery.
[INTO [user.] {PLAN_TABLEltable)] [Notl greater than or equal to x and Iess than
FOR sql_statement or equal to y.
Determines the plan ORACLE follows to execute a sqCstatement. TRUE if a subquery returns [does not returnl
Inserts a row into a table for each step of the execution plan. For at least one raw.
information on how to interpret an execution plan, refer to the
ORACLE RDBM5 Performance Tuning Cuide, Part No. 5317-V6.0.
Matches [does not match] a specified pattern.
'%' matches any sequence of characters; '_'
matches any single character.
ls [notl null.
SCC or CC Century; '5' prefixes "Be" date with '-'o Number of "9"s determines length of returned
character.
YYYYor SYYYY Year; '5' prefixes "BC"date with '-'o
'0999' Prefixes value with leading zeroes.
YYVor YY or Y Last 3, 2, or 1 digit(s) of year.
Y,YYV Year with comma in this position. '$9999' Prefixes value with a dollar signo
SYEAR or YEAR Year, spelled out; '5' prefixes "Be" date with '-'. 'B9999' Returns zero value as blank, instead of "O".
BC or AD BC/ AD indicator. '9999MI' Returns "_"after negative values.
B.e. or A.D. BC/ AD indicator with periods. '9999PR' Returns negative values in <angle brackets>.
Q Quarter of year (1, 2,3, 4; JAN-MAR = 1).. '9,999' Returns value with a comma in this position.
MM Month of year (01-12; JAN=Ol).
'99.99' Returns value with a decimal point in this position.
MüNTH Month name, padded with blanks to 9 characters.
'999V99' Multiplies value by IOn, where n is the number
MüN Name of month, 3-letter abbreviation.
of "9"s after the "V".
WW or W Week of year (1-52) or month (1-5).
Returns value in scientific notation.
DDD or DD or D Day of year (1-366)or month 0-31) or week (1-7).
fmt must contain exactly four "E"s.
DAY Name of day, padded with blanks to 9 characters.
Returns value converted from Julian date to
DY Name of day, 3-letter abbreviation.
'MM/DD/YY' date formato
J Julian day (days since December 31,4713 BC).
AM or PM Meridian indicator.
A.M. or P.M. Meridian indicator with periods.
HH and HH12 Hour of day (1-12). Pseudo-eolumns are similar to table columns. You can query any of these
pseudo-columns, but you cannot change their values with DML statements:
HH24 Hour of day (0-23).
MI Minute (O-59). Column Name Value
SS or SSSSS Second (O-59)or seconds past midnight (0-86399). sequence.CURRV AL Current value of sequence for the current session.
l. , Punctuation is returned exactly as specified. sequence.NEXTV AL Next value of sequence for the current session.
" " Quoted string is returned exactly as specified. table.LEVEL 1 for a root node, 2 for a child of a root, etc.
You can add this prefix to date format elements: Used in the CONNECT BYclause of the
SELECTstatement.
FM "Fill mode." Suppresses blank padding when
Value that uniquely identifies a single row
prefixed to MONTH or DAY.
among other rows in the table.
FM is a toggle. Use FM twice to reenable
ROWID values are of datatype ROWID,not
blank padding.
NUMBERor CHAR.
You can add these suffixes to date format elements:
Position of a single row among other rows
TH Ordinal number ("DDTH" for "4TH"). selected by a query.
sr 5pelled-out number ("DDSP"for "FOUR"). ORACLE selects rows in an arbitrary order
SPTH and THSP Spelled-out ordinal number ("DDSPTH" for and evaluates ROWNUM before sorting rows
"FOURTH"). for an ORDER BYclause.
Data Dictionary Views
The Data Dictionary contains information about database objects, users, and events.
You can access this inforrnation through these views of the Data Dictionary:
Names of database objects, such as tables or columns, must: View Description
be between 1 and 30 characters long, except for database names, which Columns of all tables, views, and clusters
can be no longer than 8 characters accessible to the user.
begin with a letter A-Z
contain only the characters A-Z, 0-9, $, #, and _ ACCESSIBLE_TABLES Tables and views accessible to the user.
not contain quotation marks ALL_CATALOG Tables, views, synonyms, and sequences
not duplicate a SQL reserved word accessible to the user.
not duplicate the name of another object
Comrnents on colurnns of tables and views
Unless a name is always enclosed in quotation marks when used in statements,
accessible to the user.
the name is not case-sensitive.
ALL_COL_GRANTS Synonyrn for COLUMN]RIVILEGES.
ALL_COL_GRANTS_MADE Grants on colurnns for which the user is the
owner or the grantor.
SQL reserved words have special meanings in SQL statements. You may not Grants on columns for which the user or
use these words as names for database objects: PUELlC is the grantee.
ALL_ CONSTRAINTS Constraints on tables accessible to the user.
ACCESS DEFAULT" INITIAL ON* SMALLINT"
DELETE* INSERT" ALL_CONS_COLUMNS Primary, unique, and foreign key columns in
ADD ONLINE START
ALL* DESe' INTEGER* OPTION* SUCCESSFUL constraints owned by the user or on tables
ALTER* DISTINCT" INTERSECT OR* SYNONYM owned by the user.
ANO' DROP INTO* ORDER* SYSDATE ALL_DB_LINKS Database links accessible to the user.
ANY* ELSE IS* PCTFREE TABLE* ALL_DEF_AUDIT_OPTS Default auditing options for newly created objects.
AS* EXCLUSIVE LEVEL PRIOR THEN ALL_INDEXES Indexes on tables and clusters accessible to the
ASC* EXISTS* LIKE* PRIVILEGES* TO*
user.
AUDIT FILE LOCK PUBLlC* TRIGGER
BETWEEN* FLOAT" LONG RAW UID Columns cornprising indexes on tables and
BY* FOR* MAXEXTENTS RENAME UNION* cluster s accessible to the user.
CHAR* FROM* MINUS RESOURCE UNIQUE* ALL_OBJECTS Objects accessible to the user.
CHECK* GRANT* MODE REVOKE* UPDATE* ALL_SEQUENCES Sequences accessible to the user.
CLUSTER GRAPHIC MODIFY* ROW USER*
ALL_SYNONYMS Synonyms accessible to the user.
COLUMN GROUP* NOAUDIT ROWID VALIDATE
COMMENT HAVING* NOCOMPRESS ROWNUM VALUES* ALL_TABLES Tables accessible to the user.
COMPRESS IDENTIFIED NOT ROWS VARCHAR* ALL_TAB_COLUMNS Synonym for ACCESSIBLE_COLUMNS.
CONNECf IF NOWAIT SELECT* VARGRAPHIC ALL_TAB_COMMENTS Comments on al! tables and views accessible
CREATE* IMMEDIATE* NULL* SESSION* VIEW* to the user.
CURRENT* IN* NUMBER SET" WHENEVER*
DATE INCREMENT OF* WHERE* ALL_TAB_GRANTS Synonyrn for T ABLE]RIVILEGES.
SHARE
DBA INDEX OFFLINE SIZE WITH* ALL_TAB_GRANTS_MADE Grants on objects for which the user is the
DECIMAL* owner or the grantor.
Grants on tables for which the user or PUBLlC
* These words are also ANSI reserved words.
is the grantee.
ALL_USERS Al! database users.
ALL_VIEWS Views accessible to the user.
AUDIT_ACnONS Names and codes of audit trail action types.
CAT Synonym for USER_CATALOC. DBA_SYNONYMS All synonyms in the database.
CLU Synonym for USER_CLUSTERS. DBA_SYS_AUDIT_OPTS Current system auditing options.
COLS Synonym for USER_TAB_COLUMNS. DBA_TABLES All tables in the database.
COLUMN]RIVILEGES Grants on columns for which the user is the DBA_TABLESPACES Al! tablespaces.
grantor, grantee, or owner, or PUBLlC is the DBA_TAB_AUDIT_OPTS Auditing options for all database tables and views.
grantee. DBA_TAB_COLUMNS Columns of all database tables, views, and
Foreign key columns in constraints owned by clusters.
the user or on tables accessible to the user. DBA_TAB_COMMENTS Comments on all database tables and views.
CONSTRAINT_DEFS Constraints on tables accessible to the user. DBA_TAB_GRANTS AII grants on database objects.
DBA_AUDIT _CONNECT Synonym for USER~AUDIT_CONNECT. DBA_TS_QUOTAS Tablespace quotas for all users.
DBA_AUDIT_DBA Audit trail entries for actions requiring DBA DBA_USERS AII database users.
privilege. DBA_VIEWS Al! views in the database.
Audit trail entries for any action resulting in Synonym for DICTIONARY.
DICT
an error because a specified database object
DI CTIONARY Data Dictionary tables and views.
does not exist.
DICT_COLUMNS Columns in Data Dictionary tables and views.
DBA_AUDIT_RESOURCE Synonym for USER_AUDIT_RESOURCE.
DUAL Dummy table with one row and one column.
DBA_AUDIT_ TRAIL Synonym for USER_AUDIT _TRAIL.
IND Synonym for USER_INDEXES.
DBA_CATALOG AII tables, views, synonyrns, and sequences in
the database. MYPRIVS Synonym for USER_USERS.
DBA_ CLUSTERS Al! clusters in the database. OB] Synonym for USER_OB]ECTS.
DBA_CLU_COLUMNS Mapping of table columns to al! cluster columns. SEQ Synonym for USER_SEQUENCES.
DBA_ COL_ COMMENTS Comments on columns of all tables and views SYN Synonym for USER_SYNONYMS.
in the database. TABLE_PRIVILEGES Grants on objects for which the user is the
DBA_COL_GRANTS Al! grants on columns in the database. grantor, grantee, or owner, or PUBLlC is the
Constraints on all database tables. grantee.
DBA_CONSTRAINTS
AII database columns used in constraints. TABS Synonyms for USER_TABLES.
DBA_CONS_COLUMNS
Cross reference of all views, synonyms, and USER_AUDIT_ CONNECT Audit trail entries for user logons/logoffs.
DBA_CROSS_REFS
constraints in the databa se. USER_AUDIT_RESOURCE Audit trail entries for user actions that create
Database files. or drop database objects.
DBA_DA TA_FILES
Al! database links in the database. USER_AUDIT _TRAIL Audit trail entries relevant to the user.
DBA_DB_LINKS
USER_CATALOG Tables, views, synonyms, and sequences
DBA_EXP _FILES Export files.
owned by the user.
DBA_EXP _OB]ECTS Objects that have been incrementally exported.
USER_CLUSTERS Clusters owned by the user.
DBA_EXP _VERSION Version number of last export session.
USER_CLU_COLUMNS Mapping of table columns to the user's cluster
DBA_EXTENTS Extents comprising all segments in the database.
columns.
DBA_FREE_SPACE Free extents in al! tablespaces in the database.
Comments on columns of the tables and views
DBA_INDEXES Al! indexes in the databa se. owned by the user.
DBA_IND _COLUMNS Columns comprising indexes on al! tables and Grants on columns for which the user is the
clusters in the database. owner, grantor, or grantee.
DBA_OB]ECTS All objects in the database. USER_ COL_ GRANTS_MADE Grants on columns of objects owned by the user.
DBA_ROLLBACK_SEGS Rollback segments. USER_ COL_ GRANTS_RECD Grants on columns for which the user is the
DBA_SEGMENTS Storage allocated for all database segments. grantee.
DBA_SEQUENCES Al! sequences in the databa se.
USER_ CONSTRAINTS Constraints owned by the user.
USER_ CONS_ COLUMNS Columns in eonstraints owned by the user.
USER_CROSS_REFS Cross references for views, synonyms, and
eonstraints owned by the user.
USER_DB_LINKS Database links owned by the user.
USER_EXTENTS Extents eomprising segments owned by the user.
USER_FREE_SP ACE Free extents in tablespaees available to the user.
USER_INDEXES Indexes owned by the user.
USER_IND_COLUMNS Columns eomprising the user's indexes or
indexes on the user's tables or C!usters.
USER_OBJECTS Objeets owned by the liser.
USER_SEGMENTS Storage alloeated for segments owned by the
user.
USER_SEQUENCES Sequenees owned by the user.
USER_SYNONYMS The user's private synonyms.
USER_TABLES Tables owned by the user.
USER_ TABLESPACES Tablespaees available to the user.
USER_TAB_AUDIT_OPTS Auditing options for the user's tables and views.
USER_TAB_COLUMNS Columns of the user's tables, views, and C!usters.
USER_TAB_COMMENTS Comments on the user's tables and views.
USER_TAB_GRANTS Grants on objeets for which the user is the
owner, grantor, or grantee.
USER_ TAB_GRANTS_MADE Grants on objects owned by the user.
USER_ TAB_ GRANTS_RECD Grants on objeets for which the user is the
grantee.
USER_TS_QUOTAS Tablespaee quotas for the user.
USER_USERS Privileges of the eurrent user.
USER_VIEWS Views owned by the user.