
- •Contents
- •Send Us Your Comments
- •Preface
- •What’s New in SQL Reference?
- •1 Introduction to Oracle SQL
- •History of SQL
- •SQL Standards
- •Embedded SQL
- •Lexical Conventions
- •Tools Support
- •2 Basic Elements of Oracle SQL
- •Datatypes
- •Oracle Built-in Datatypes
- •ANSI, DB2, and SQL/DS Datatypes
- •Oracle-Supplied Types
- •"Any" Types
- •XML Types
- •Spatial Type
- •Media Types
- •Datatype Comparison Rules
- •Data Conversion
- •Literals
- •Text Literals
- •Integer Literals
- •Number Literals
- •Interval Literals
- •Format Models
- •Number Format Models
- •Date Format Models
- •String-to-Date Conversion Rules
- •XML Format Model
- •Nulls
- •Nulls in SQL Functions
- •Nulls with Comparison Conditions
- •Nulls in Conditions
- •Pseudocolumns
- •CURRVAL and NEXTVAL
- •LEVEL
- •ROWID
- •ROWNUM
- •XMLDATA
- •Comments
- •Comments Within SQL Statements
- •Comments on Schema Objects
- •Hints
- •Database Objects
- •Schema Objects
- •Nonschema Objects
- •Parts of Schema Objects
- •Schema Object Names and Qualifiers
- •Schema Object Naming Rules
- •Schema Object Naming Examples
- •Schema Object Naming Guidelines
- •Syntax for Schema Objects and Parts in SQL Statements
- •How Oracle Resolves Schema Object References
- •Referring to Objects in Other Schemas
- •Referring to Objects in Remote Databases
- •Referencing Object Type Attributes and Methods
- •3 Operators
- •About SQL Operators
- •Unary and Binary Operators
- •Operator Precedence
- •Arithmetic Operators
- •Concatenation Operator
- •Set Operators
- •4 Expressions
- •About SQL Expressions
- •Simple Expressions
- •Compound Expressions
- •CASE Expressions
- •CURSOR Expressions
- •Datetime Expressions
- •Function Expressions
- •INTERVAL Expressions
- •Object Access Expressions
- •Scalar Subquery Expressions
- •Type Constructor Expressions
- •Variable Expressions
- •Expression Lists
- •5 Conditions
- •About SQL Conditions
- •Condition Precedence
- •Comparison Conditions
- •Simple Comparison Conditions
- •Group Comparison Conditions
- •Logical Conditions
- •Membership Conditions
- •Range Conditions
- •Null Conditions
- •EQUALS_PATH
- •EXISTS Conditions
- •LIKE Conditions
- •IS OF type Conditions
- •UNDER_PATH
- •Compound Conditions
- •6 Functions
- •SQL Functions
- •Single-Row Functions
- •Aggregate Functions
- •Analytic Functions
- •Object Reference Functions
- •Alphabetical Listing of SQL Functions
- •ACOS
- •ADD_MONTHS
- •ASCII
- •ASCIISTR
- •ASIN
- •ATAN
- •ATAN2
- •BFILENAME
- •BITAND
- •CAST
- •CEIL
- •CHARTOROWID
- •COALESCE
- •COMPOSE
- •CONCAT
- •CONVERT
- •CORR
- •COSH
- •COUNT
- •COVAR_POP
- •COVAR_SAMP
- •CUME_DIST
- •CURRENT_DATE
- •CURRENT_TIMESTAMP
- •DBTIMEZONE
- •DECODE
- •DECOMPOSE
- •DENSE_RANK
- •DEPTH
- •DEREF
- •DUMP
- •EMPTY_BLOB, EMPTY_CLOB
- •EXISTSNODE
- •EXTRACT (datetime)
- •EXTRACT (XML)
- •EXTRACTVALUE
- •FIRST
- •FIRST_VALUE
- •FLOOR
- •FROM_TZ
- •GREATEST
- •GROUP_ID
- •GROUPING
- •GROUPING_ID
- •HEXTORAW
- •INITCAP
- •INSTR
- •LAST
- •LAST_DAY
- •LAST_VALUE
- •LEAD
- •LEAST
- •LENGTH
- •LOCALTIMESTAMP
- •LOWER
- •LPAD
- •LTRIM
- •MAKE_REF
- •MONTHS_BETWEEN
- •NCHR
- •NEW_TIME
- •NEXT_DAY
- •NLS_CHARSET_DECL_LEN
- •NLS_CHARSET_ID
- •NLS_CHARSET_NAME
- •NLS_INITCAP
- •NLS_LOWER
- •NLSSORT
- •NLS_UPPER
- •NTILE
- •NULLIF
- •NUMTODSINTERVAL
- •NUMTOYMINTERVAL
- •PATH
- •PERCENT_RANK
- •PERCENTILE_CONT
- •PERCENTILE_DISC
- •POWER
- •RANK
- •RATIO_TO_REPORT
- •RAWTOHEX
- •RAWTONHEX
- •REFTOHEX
- •REGR_ (Linear Regression) Functions
- •REPLACE
- •ROUND (number)
- •ROUND (date)
- •ROW_NUMBER
- •ROWIDTOCHAR
- •ROWIDTONCHAR
- •RPAD
- •RTRIM
- •SESSIONTIMEZONE
- •SIGN
- •SINH
- •SOUNDEX
- •SQRT
- •STDDEV
- •STDDEV_POP
- •STDDEV_SAMP
- •SUBSTR
- •SYS_CONNECT_BY_PATH
- •SYS_CONTEXT
- •SYS_DBURIGEN
- •SYS_EXTRACT_UTC
- •SYS_GUID
- •SYS_TYPEID
- •SYS_XMLAGG
- •SYS_XMLGEN
- •SYSDATE
- •SYSTIMESTAMP
- •TANH
- •TO_CHAR (character)
- •TO_CHAR (datetime)
- •TO_CHAR (number)
- •TO_CLOB
- •TO_DATE
- •TO_DSINTERVAL
- •TO_MULTI_BYTE
- •TO_NCHAR (character)
- •TO_NCHAR (datetime)
- •TO_NCHAR (number)
- •TO_NCLOB
- •TO_NUMBER
- •TO_SINGLE_BYTE
- •TO_TIMESTAMP
- •TO_TIMESTAMP_TZ
- •TO_YMINTERVAL
- •TRANSLATE
- •TRANSLATE ... USING
- •TREAT
- •TRIM
- •TRUNC (number)
- •TRUNC (date)
- •TZ_OFFSET
- •UNISTR
- •UPDATEXML
- •UPPER
- •USER
- •USERENV
- •VALUE
- •VAR_SAMP
- •VARIANCE
- •VSIZE
- •WIDTH_BUCKET
- •XMLAGG
- •XMLCOLATTVAL
- •XMLCONCAT
- •XMLELEMENT
- •XMLFOREST
- •XMLSEQUENCE
- •XMLTRANSFORM
- •ROUND and TRUNC Date Functions
- •User-Defined Functions
- •Prerequisites
- •Name Precedence
- •7 Common SQL DDL Clauses
- •allocate_extent_clause
- •constraints
- •deallocate_unused_clause
- •file_specification
- •logging_clause
- •parallel_clause
- •physical_attributes_clause
- •storage_clause
- •8 SQL Queries and Subqueries
- •About Queries and Subqueries
- •Creating Simple Queries
- •Hierarchical Queries
- •The UNION [ALL], INTERSECT, MINUS Operators
- •Sorting Query Results
- •Joins
- •Using Subqueries
- •Unnesting of Nested Subqueries
- •Selecting from the DUAL Table
- •Distributed Queries
- •9 SQL Statements: ALTER CLUSTER to ALTER SEQUENCE
- •Types of SQL Statements
- •Organization of SQL Statements
- •ALTER CLUSTER
- •ALTER DATABASE
- •ALTER DIMENSION
- •ALTER FUNCTION
- •ALTER INDEX
- •ALTER INDEXTYPE
- •ALTER JAVA
- •ALTER MATERIALIZED VIEW
- •ALTER MATERIALIZED VIEW LOG
- •ALTER OPERATOR
- •ALTER OUTLINE
- •ALTER PACKAGE
- •ALTER PROCEDURE
- •ALTER PROFILE
- •ALTER RESOURCE COST
- •ALTER ROLE
- •ALTER ROLLBACK SEGMENT
- •ALTER SEQUENCE
- •10 SQL Statements: ALTER SESSION to ALTER SYSTEM
- •ALTER SESSION
- •ALTER SYSTEM
- •ALTER TABLE
- •ALTER TABLESPACE
- •ALTER TRIGGER
- •ALTER TYPE
- •ALTER USER
- •ALTER VIEW
- •ANALYZE
- •ASSOCIATE STATISTICS
- •AUDIT
- •CALL
- •COMMENT
- •COMMIT
- •13 SQL Statements: CREATE CLUSTER to CREATE JAVA
- •CREATE CLUSTER
- •CREATE CONTEXT
- •CREATE CONTROLFILE
- •CREATE DATABASE
- •CREATE DATABASE LINK
- •CREATE DIMENSION
- •CREATE DIRECTORY
- •CREATE FUNCTION
- •CREATE INDEX
- •CREATE INDEXTYPE
- •CREATE JAVA
- •14 SQL Statements: CREATE LIBRARY to CREATE SPFILE
- •CREATE LIBRARY
- •CREATE MATERIALIZED VIEW
- •CREATE MATERIALIZED VIEW LOG
- •CREATE OPERATOR
- •CREATE OUTLINE
- •CREATE PACKAGE
- •CREATE PACKAGE BODY
- •CREATE PFILE
- •CREATE PROCEDURE
- •CREATE PROFILE
- •CREATE ROLE
- •CREATE ROLLBACK SEGMENT
- •CREATE SCHEMA
- •CREATE SEQUENCE
- •CREATE SPFILE
- •15 SQL Statements: CREATE SYNONYM to CREATE TRIGGER
- •CREATE SYNONYM
- •CREATE TABLE
- •CREATE TABLESPACE
- •CREATE TEMPORARY TABLESPACE
- •CREATE TRIGGER
- •CREATE TYPE
- •CREATE TYPE BODY
- •CREATE USER
- •CREATE VIEW
- •DELETE
- •DISASSOCIATE STATISTICS
- •DROP CLUSTER
- •DROP CONTEXT
- •DROP DATABASE LINK
- •DROP DIMENSION
- •DROP DIRECTORY
- •DROP FUNCTION
- •DROP INDEX
- •DROP INDEXTYPE
- •DROP JAVA
- •DROP LIBRARY
- •DROP MATERIALIZED VIEW
- •DROP MATERIALIZED VIEW LOG
- •DROP OPERATOR
- •DROP OUTLINE
- •DROP PACKAGE
- •DROP PROCEDURE
- •DROP PROFILE
- •DROP ROLE
- •DROP ROLLBACK SEGMENT
- •17 SQL Statements: DROP SEQUENCE to ROLLBACK
- •DROP SEQUENCE
- •DROP SYNONYM
- •DROP TABLE
- •DROP TABLESPACE
- •DROP TRIGGER
- •DROP TYPE
- •DROP TYPE BODY
- •DROP USER
- •DROP VIEW
- •EXPLAIN PLAN
- •GRANT
- •INSERT
- •LOCK TABLE
- •MERGE
- •NOAUDIT
- •RENAME
- •REVOKE
- •ROLLBACK
- •18 SQL Statements: SAVEPOINT to UPDATE
- •SAVEPOINT
- •SELECT
- •SET CONSTRAINT[S]
- •SET ROLE
- •SET TRANSACTION
- •TRUNCATE
- •UPDATE
- •Required Keywords and Parameters
- •Optional Keywords and Parameters
- •Syntax Loops
- •Multipart Diagrams
- •Database Objects
- •ANSI Standards
- •ISO Standards
- •Oracle Compliance
- •FIPS Compliance
- •Oracle Extensions to Standard SQL
- •Character Set Support
- •Using Extensible Indexing
- •Using XML in SQL Statements
- •Index

deallocate_unused_clause
deallocate_unused_clause
Purpose
Use the deallocate_unused_clause to explicitly deallocate unused space at the end of a database object segment and make the space available for other segments in the tablespace.
You can deallocate unused space using the following statements:
■ALTER CLUSTER (see ALTER CLUSTER on page 9-6)
■ALTER INDEX: to deallocate unused space from the index, an index partition, or an index subpartition (see ALTER INDEX on page 9-62)
■ALTER MATERIALIZED VIEW: to deallocate unused space from the overflow segment of an index-organized materialized view (see ALTER MATERIALIZED VIEW on page 9-90)
■ALTER TABLE: to deallocate unused space from the table, a table partition, a table subpartition, the mapping table of an index-organized table, the overflow segment of an index-organized table, or a LOB storage segment (see ALTER TABLE on page 11-2)
Syntax
deallocate_unused_clause::=
K
M
KEEP integer
DEALLOCATE UNUSED
Semantics
This section describes the semantics of the deallocate_unused_clause. For additional information, refer to the SQL statement in which you set or reset this clause for a particular database object.
Note: You cannot specify both the deallocate_unused_ clause and the allocate_extent_clause in the same statement.
Common SQL DDL Clauses 7-37

deallocate_unused_clause
Oracle frees only unused space above the high water mark (that is, the point beyond which database blocks have not yet been formatted to receive data). Oracle deallocates unused space beginning from the end of the object and moving toward the beginning of the object to the high water mark.
If an extent is completely contained in the deallocation, then the whole extent is freed for reuse. If an extent is partially contained in the deallocation, then the used part up to the high water mark becomes the extent, and the remaining unused space is freed for reuse.
Oracle credits the amount of the released space to the user quota for the tablespace in which the deallocation occurs.
The exact amount of space freed depends on the values of the INITIAL, MINEXTENTS, and NEXT storage parameters.
See Also: storage_clause on page 7-56 for a description of these parameters
KEEP integer
Specify the number of bytes above the high water mark that the segment of the database object is to have after deallocation.
■If you omit KEEP and the high water mark is above the size of INITIAL and MINEXTENTS, then all unused space above the high water mark is freed. When the high water mark is less than the size of INITIAL or MINEXTENTS, then all unused space above MINEXTENTS is freed.
■If you specify KEEP, then the specified amount of space is kept and the remaining space is freed. When the remaining number of extents is less than MINEXTENTS, then MINEXTENTS is adjusted to the new number of extents. If the initial extent becomes smaller than INITIAL, then INITIAL is adjusted to the new size.
■In either case, Oracle sets the value of the NEXT storage parameter to the size of the last extent that was deallocated.
7-38 Oracle9i SQL Reference

file_specification
file_specification
Purpose
Use one of the file_specification forms to specify a file as a datafile or tempfile, or to specify a group of one or more files as a redo log file group.
A file_specification can appear in the following statements:
■CREATE CONTROLFILE (see CREATE CONTROLFILE on page 13-15)
■CREATE DATABASE (see CREATE DATABASE on page 13-23)
■ALTER DATABASE (see ALTER DATABASE on page 9-11)
■CREATE TABLESPACE (see CREATE TABLESPACE on page 15-80)
■CREATE TEMPORARY TABLESPACE (see CREATE TEMPORARY TABLESPACE on page 15-92)
■ALTER TABLESPACE (see ALTER TABLESPACE on page 11-102)
Prerequisites
You must have the privileges necessary to issue one of the statements listed in the preceding section.
Syntax
file_specification::=
datafile_tempfile_spec
redo_log_file_spec
datafile_tempfile_spec::=
|
|
|
|
|
K |
|
|
|
|
|
|
M |
|
’ |
filename |
’ |
SIZE |
integer |
REUSE |
autoextend_clause |
Common SQL DDL Clauses 7-39

file_specification
redo_log_file_spec::=
’ |
filename |
’ |
|
|
|
|
K |
|
|
|
|
|
|
|
|
|
|
, |
|
|
|
|
M |
|
|
|
|
|
|
|
|
( |
’ |
filename |
’ |
) |
SIZE |
integer |
REUSE |
autoextend_clause::=
OFF |
|
|
|
|
K |
AUTOEXTEND |
|
M |
|
|
|
NEXT |
integer |
maxsize_clause |
ON |
|
|
maxsize_clause::=
UNLIMITED
K
MAXSIZE
M
integer
Semantics
This section describes the semantics of file_specification. For additional information, refer to the SQL statement in which you specify a datafile, tempfile, or redo log file.
’filename’
For a new file, filename is the name of the new file. If you are not using Oraclemanaged files, then you must specify filename or the statement fails. However, if you are using Oracle-managed files, then filename is optional, as are the remaining clauses of the specification. In this case, Oracle creates a unique name for the file and saves it in the directory specified by either the DB_CREATE_FILE_DEST initialization parameter (for any type of file) or by the DB_CREATE_ONLINE_LOG_ DEST_n initialization parameter (which takes precedence over DB_CREATE_FILE_ DEST for log files).
7-40 Oracle9i SQL Reference

file_specification
See Also: Oracle9i Database Administrator’s Guide for more information on Oracle-managed files, "Specifying a Datafile: Example" on page 7-43, and "Specifying a Log File: Example" on page 7-43
For an existing file, you must specify a filename. Specify the name of either a datafile, tempfile, or a redo log file member. The filename can contain only singlebyte characters from 7-bit ASCII or EBCDIC character sets. Multibyte characters are not valid.
A redo log file group can have one or more members (copies). Each filename must be fully specified according to the conventions for your operating system.
SIZE Clause
Specify the size of the file in bytes. Use K or M to specify the size in kilobytes or megabytes.
■For undo tablespaces, you must specify the SIZE clause for each datafile. For other tablespaces, you can omit this parameter if the file already exists, or if you are creating an Oracle-managed file.
■If you omit this clause when creating an Oracle-managed file, then Oracle creates a 100M file.
■The size of a tablespace must be one block greater than the sum of the sizes of the objects contained in it.
See Also: Oracle9i Database Administrator’s Guide for information on Automatic Undo Management and undo tablespaces and "Adding a Log File: Example" on page 7-43
REUSE
Specify REUSE to allow Oracle to reuse an existing file. You must specify REUSE if you specify a filename that already exists.
■If the file already exists, then Oracle reuses the filename and applies the new size (if you specify SIZE) or retains the original size.
■If the file does not exist, then Oracle ignores this clause and creates the file.
Restriction on the REUSE Clause You cannot specify REUSE unless you have specified filename.
Common SQL DDL Clauses 7-41

file_specification
Note: Whenever Oracle uses an existing file, the file’s previous contents are lost.
See Also: "Adding a Datafile: Example" on page 7-44 and "Adding a Log File: Example" on page 7-43
autoextend_clause
Use the autoextend_clause to enable or disable the automatic extension of a new datafile or tempfile. If you omit this clause:
■For Oracle-managed files:
■If you specify SIZE, Oracle creates a file of the specified size with
AUTOEXTEND disabled.
■If you do not specify SIZE, Oracle creates a 100M file with AUTOEXTEND enabled and MAXSIZE unlimited.
■For user-managed files, with or without SIZE specified, Oracle creates a file with AUTOEXTEND disabled.
ON Specify ON to enable autoextend.
OFF Specify OFF to turn off autoextend if is turned on.
Note: When you turn off autoextend, the values of NEXT and MAXSIZE are set to zero. If you turn autoextend back on in a subsequent statement, you must reset these values.
NEXT Use the NEXT clause to specify the size in bytes of the next increment of disk space to be allocated automatically when more extents are required. Use K or M to specify this size in kilobytes or megabytes. The default is the size of one data block.
MAXSIZE Use the MAXSIZE clause to specify the maximum disk space allowed for automatic extension of the datafile.
UNLIMITED Use the UNLIMITED clause if you do not want to limit the disk space that Oracle can allocate to the datafile or tempfile.
7-42 Oracle9i SQL Reference

file_specification
Restriction on the autoextend_clause You cannot specify this clause as part of datafile_tempfile_spec in a CREATE CONTROLFILE statement or in an
ALTER DATABASE CREATE DATAFILE clause.
Examples
Specifying a Log File: Example The following statement creates a database named payable that has two redo log file groups, each with two members, and one datafile:
CREATE DATABASE payable
LOGFILE GROUP 1 (’diska:log1.log’, ’diskb:log1.log’) SIZE 50K, GROUP 2 (’diska:log2.log’, ’diskb:log2.log’) SIZE 50K
DATAFILE ’diskc:dbone.dat’ SIZE 30M;
The first file specification in the LOGFILE clause specifies a redo log file group with the GROUP value 1. This group has members named ’diska:log1.log’ and ’diskb:log1.log’, each 50 kilobytes in size.
The second file specification in the LOGFILE clause specifies a redo log file group with the GROUP value 2. This group has members named ’diska:log2.log’ and ’diskb:log2.log’, also 50 kilobytes in size.
The file specification in the DATAFILE clause specifies a datafile named ’diskc:dbone.dat’, 30 megabytes in size.
Each file specification specifies a value for the SIZE parameter and omits the REUSE clause, so none of these files can already exist. Oracle must create them.
Adding a Log File: Example The following statement adds another redo log file group with two members to the payable database:
ALTER DATABASE payable
ADD LOGFILE GROUP 3 (’diska:log3.log’, ’diskb:log3.log’)
SIZE 50K REUSE;
The file specification in the ADD LOGFILE clause specifies a new redo log file group with the GROUP value 3. This new group has members named ’diska:log3.log’ and ’diskb:log3.log’, each 50 kilobytes in size. Because the file specification specifies the REUSE clause, each member can (but need not) already exist.
Specifying a Datafile: Example The following statement creates a tablespace named stocks that has three datafiles:
Common SQL DDL Clauses 7-43

file_specification
CREATE TABLESPACE stocks
DATAFILE ’stock1.dat’ SIZE 10M, ’stock2.dat’ SIZE 10M, ’stock3.dat’ SIZE 10M;
The file specifications for the datafiles specify files named ’diskc:stock1.dat’, ’diskc:stock2.dat’, and ’diskc:stock3.dat’.
Adding a Datafile: Example The following statement alters the stocks tablespace and adds a new datafile:
ALTER TABLESPACE stocks
ADD DATAFILE ’stock4.dat’ SIZE 10M REUSE;
The file specification specifies a datafile named ’diskc:stock4.dat’. If the filename does not exist, then Oracle simply ignores the REUSE keyword.
7-44 Oracle9i SQL Reference