
- •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

ANSI Standards
The following documents of the American National Standards Institute (ANSI) relate to SQL:
■ANSI/ISO/IEC 9075-1:1999, Information technology—Database languages—SQL—Part 1: Framework (SQL/Framework)
■ ANSI/ISO/IEC 9075-1:1999/Amd.1:2000
■ANSI/ISO/IEC 9075-2:1999, Information technology—Database languages—SQL—Part 2: Foundation (SQL/Foundation)
■ANSI/ISO/IEC 9075-5:1999, Information technology—Database languages—SQL—Part 5: Host Language Bindings (SQL/Bindings)
You can obtain a copy of ANSI standards from this address:
American National Standards Institute
11 West 42nd Street
New York, NY 10036 USA
Telephone: +1.212.642.4900
Fax: +1.212.398.0023
or from their Web site:
http://webstore.ansi.org/ansidocstore/default.asp
A subset of ANSI standards, including the SQL standard, are X3 or NCITS standards. You can obtain these from the National Committee for Information Technology Standards (NCITS) at:
http://www.cssinfo.com/ncitsgate.html
ISO Standards
The following documents of the International Organization for Standardization (ISO) relate to SQL:
■ISO/IEC 9075-1:1999, Information technology—Database languages—SQL—Part 1: Framework (SQL/Framework)
■ ISO/IEC 9075-1:1999/Amd.1:2000
■ISO/IEC 9075-2:1999, Information technology—Database languages—SQL—Part 2: Foundation (SQL/Foundation)
B-2 Oracle9i SQL Reference

■ISO/IEC 9075-5:1999, Information technology—Database languages—SQL—Part 5: Host Language Bindings (SQL/Bindings)
You can obtain a copy of ISO standards from this address:
International Organization for Standardization 1 Rue de Varembé
Case postale 56
CH-1211, Geneva 20, Switzerland Phone: +41.22.749.0111
Fax: +41.22.733.3430
Web site: http://www.iso.ch/
or from their web store:
http://www.iso.ch/cate/cat.html
Oracle Compliance
The ANSI and ISO SQL standards require conformance claims to state the type of conformance and the implemented facilities. The following products provide full or partial conformance with the ANSI and ISO standards as described in the tables that follow:
■
■
■
■
■
■
■
■
■
Oracle9i database server
Pro*C/C++, release 9.2.0
Pro*COBOL, release 9.2.0
Pro*Fortran, release 1.8.77
SQL Module for Ada (Mod*Ada), release 9.2.0
Pro*COBOL 1.8, release 1.8.77
Pro*PL/I, release 1.6.28
OTT, release 9.2.0.
OTT8, release 8.1.8
The Core SQL:1999 features that Oracle fully supports are listed in Table B–1:
Table B–1 |
Fully Supported Core SQL:1999 Features |
Feature ID |
Feature |
|
|
E011 |
Numeric data types |
|
|
Oracle and Standard SQL B-3

Table B–1 |
(Cont.) Fully Supported Core SQL:1999 Features |
|
|
Feature ID |
Feature |
|
|
E031 |
Identifiers |
|
|
E061 |
Basic predicates and search conditions |
|
|
E081 |
Basic privileges |
|
|
E091 |
Set functions |
|
|
E101 |
Basic data manipulation |
|
|
E111 |
Single row SELECT statement |
|
|
E131 |
Null value support (nulls in lieu of values) |
|
|
E141 |
Basic integrity constraints |
|
|
E151 |
Transaction support |
|
|
E152 |
Basic SET TRANSACTION statement |
|
|
E153 |
Updatable queries with subqueries |
|
|
E161 |
SQL comments using leading double minus |
|
|
E171 |
SQLSTATE support |
|
|
F041 |
Basic joined table |
|
|
F051 |
Basic date and time |
|
|
F081 |
UNION and EXCEPT in views |
|
|
F131 |
Grouped operations |
|
|
F181 |
Multiple module support |
|
|
F201 |
CAST function |
|
|
F221 |
Explicit defaults |
|
|
F261 |
CASE expressions |
|
|
F311 |
Schema definition statement |
|
|
F471 |
Scalar subquery values |
|
|
F481 |
Expanded NULL predicate |
|
|
B011 |
Embedded Ada |
|
|
B012 |
Embedded C |
|
|
B013 |
Embedded COBOL |
|
|
B-4 Oracle9i SQL Reference

Table B–1 |
(Cont.) Fully Supported Core SQL:1999 Features |
Feature ID |
Feature |
|
|
B014 |
Embedded Fortran |
|
|
T431 |
Extended grouping capabilities |
|
|
T611 |
Elementary OLAP operators |
|
|
T621 |
Enhanced numeric functions |
|
|
The Core SQL:1999 features that Oracle partially supports are listed in Table B–2:
Table B–2 Partially Supported Core SQL:1999 Features
Feature ID, Feature |
Partial Support |
|
|
|
|
E021, Character data types |
Oracle fully supports these subfeatures: |
|
|
■ E021-01, CHARACTER data type |
|
|
■ |
E021-07, Character concatenation |
|
■ E021-08, UPPER and LOWER functions |
|
|
■ |
E021-09, TRIM function |
|
■ E021-10, Implicit casting among character data types |
|
|
■ |
E021-11, Character comparison |
Oracle partially supports these subfeatures:
■ E021-02, CHARACTER VARYING data type (Oracle does not distinguish a zero-length VARCHAR string from NULL)
■ E021-03, Character literals (Oracle regards the zero-length literal ’’ as being null)
Oracle has equivalent functionality for these subfeatures:
■ E021-04, CHARACTER_LENGTH function: use LENGTH function instead
■ E021-05, OCTET_LENGTH function: use LENGTHB function instead
■ E021-06, SUBSTRING function: use SUBSTR function instead
■ E021-11, POSITION function: use INSTR function instead
Oracle and Standard SQL B-5

Table B–2 (Cont.) Partially Supported Core SQL:1999 Features
Feature ID, Feature |
Partial Support |
|
|
F031, Basic schema |
Oracle fully supports these subfeatures: |
manipulation |
■ F031-01, CREATE TABLE statement to create persistent |
|
|
|
base tables |
|
■ F031-02, CREATE VIEW statement |
|
■ F031-03, GRANT statement |
|
Oracle partially supports this subfeature: |
|
■ F031-04, ALTER TABLE statement: ADD COLUMN clause |
|
(Oracle does not support the optional keyword COLUMN in |
|
this syntax) |
|
Oracle does not support these subfeatures (because Oracle |
|
does not support the keyword RESTRICT): |
■
■
■
F031-13, DROP TABLE statement: RESTRICT clause
F031-16, DROP VIEW statement: RESTRICT clause
F031-19, REVOKE statement: RESTRICT clause
E051, Basic query |
Oracle fully supports the following subfeatures: |
specification |
■ E051-01, SELECT DISTINCT |
|
■
■
E051-02, GROUP BY clause
E051-04, GROUP BY can contain columns not in <select list>
■
■
■
E051-05, Select list items can be renamed
E051-06, HAVING clause
E051-07, Qualified * in select list
Oracle partially supports the following subfeatures:
■E051-08, Correlation names in FROM clause (Oracle supports correlation names, but not the optional AS keyword)
Oracle does not support the following subfeature:
■E051-09, Rename columns in the FROM clause
B-6 Oracle9i SQL Reference

Table B–2 (Cont.) Partially Supported Core SQL:1999 Features
Feature ID, Feature |
Partial Support |
|
|
E071, Basic query |
Oracle fully supports the following subfeatures: |
expressions |
■ E071-01, UNION DISTINCT table operator |
|
■
■
E071-02, UNION ALL able operator
E071-05, Columns combined by table operators need not have exactly the same type
■E071-06, table operators in subqueries
Oracle has equivalent functionality for the following subfeature:
■E071-03, EXCEPT DISTINCT table operator: Use MINUS instead of EXCEPT DISTINCT
E121, Basic cursor support Oracle fully supports the following subfeatures:
■E121-01, DECLARE CURSOR
■
■
■
■
■
■
■
E121-02, ORDER BY columns need not be in select list
E121-03, Value expressions in ORDER BY clause
E121-04, OPEN statement
E121-06, Positioned UPDATE statement
E121-07, Positioned DELETE statement
E121-08, CLOSE statement
E121-10, FETCH statement, implicit NEXT
|
Oracle does not support the following subfeatures: |
|
■ E121-17, WITH HOLD cursors (in the standard, a cursor is |
|
not held through a ROLLBACK, but Oracle does hold |
|
through ROLLBACK) |
|
|
F812, Basic flagging |
Oracle has a flagger, but it flags SQL-92 compliance rather than |
|
SQL:1999 compliance |
|
|
Oracle and Standard SQL B-7

Table B–2 (Cont.) Partially Supported Core SQL:1999 Features
Feature ID, Feature |
Partial Support |
|
|
|
|
T321, Basic SQL-invoked |
Oracle fully supports these subfeatures: |
|
routines |
■ |
T321-03, function invocation |
|
||
|
■ |
T321-04, CALL statement |
Oracle supports these subfeatures with syntactic differences:
■
■
T321-01, user-defined functions with no overloading
T321-02, user-defined procedures with no overloading
The Oracle syntax for CREATE FUNCTION and CREATE PROCEDURE differs from the standard as follows:
■In the standard, the mode of a parameter (IN, OUT or INOUT) comes before the parameter name, whereas in Oracle it comes after the parameter name.
■
■
The standard uses INOUT, whereas Oracle uses IN OUT.
Oracle requires either IS or AS after the return type and before the definition of the routine body, while the standard lacks these keywords.
■If the routine body is in C (for example), then the standard uses the keywords LANGUAGE C EXTERNAL NAME to name the routine, whereas Oracle uses LANGUAGE C NAME.
■If the routine body is in SQL, then Oracle uses its proprietary procedural extension called PL/SQL.
Oracle supports the following subfeatures in PL/SQL but not in Oracle SQL:
■T321-05, RETURN statement
Oracle has equivalent functionality for the features listed in Table B–3:
B-8 Oracle9i SQL Reference

Table B–3 Equivalent Functionality for Core SQL:1999 Features
Feature ID, Feature |
Equivalent Functionality |
|
|
F021, Basic information |
Oracle does not have any of the views in this feature. However, |
schema |
Oracle makes the same information available in other metadata |
|
views: |
■
■
■
■
Instead of TABLES, use ALL_TABLES.
Instead of COLUMNS, use ALL_TAB_COLUMNS.
Instead of VIEWS, use ALL_VIEWS.
However, Oracle’s ALL_VIEWS does not display whether a user view was defined WITH CHECK OPTION or if it is updatable. To see whether a view has WITH CHECK OPTION, use ALL_CONSTRAINTS, with TABLE_NAME equal to the view name and look for CONSTRAINT_TYPE equal to ’V’.
Instead of TABLE_CONSTRAINTS, REFERENTIAL_ CONSTRAINTS and CHECK_CONSTRAINTS, use ALL_ CONSTRAINTS.
However, Oracle’s ALL_CONSTRAINTS does not display whether a constraint is deferrable or initially deferred.
The Core SQL:1999 features that Oracle does not support are listed in Table B–4:
Table B–4 |
Unsupported Core SQL:1999 Features |
Feature ID |
Feature |
|
|
F501 |
Features and conformance views |
|
|
S011 |
Distinct data types |
|
|
Note: Oracle does not support E182, Module language. Although this feature is listed in Table 31 in the standard, it merely indicates that Core consists of a choice between Module language and embedded language. Module language and embedded language are completely equivalent in capability, differing only in the manner in which SQL statements are associated with the host programming language. Oracle supports embedded language.
Oracle and Standard SQL B-9