Oracle9
i
SQL Reference
Release 2 (9.2)
October 2002
Part No. A96540-02
Oracle9i SQL Reference, Release 2 (9.2)
Part No. A96540-02
Copyright © 2000, 2002 Oracle Corporation. All rights reserved.
Primary Author: Diana Lorentz
Contributing Author: Joan Gregoire
Contributors: Sundeep Abraham, Nipun Agarwal, Dave Alpern, Angela Amor, Patrick Amor, Rick
Anderson, Vikas Arora, Lance Ashdown, Hermann Baer, Subhransu Basu, Ruth Baylis, Paula Bingham,
Rae Burns, Yujie Cao, Larry Carpenter, Sivasankaran Chandrasekar, Thomas Chang, Tim Chorma, Lex de
Haan, Norbert Debes, George Eadon, Bill Gietz, Ray Guzman, John Haydu, Lilian Hobbs, Jiansheng
Huang, Ken Jacobs, Archna Johnson, Vishy Karra, Thomas Keefe, Susan Kotsovolos, Muralidhar
Krishnaprasad, Goutam Kulkarni, Paul Lane, Shilpa Lawande, Geoff Lee, Yunrui Li, Lenore Luscher,
Kevin MacDowell, Anand Manikutty, Vineet Marwah, Steve McGee, Bill McGuirk, Bill McKenna,
Meghna Mehta, Tony Morales, Sujatha Muthulingam, Michael Orlowski, Jennifer Polk, Dmitry Potapov,
Rebecca Reitmeyer, Kathy Rich, John Russell, Vivian Schupmann, Shrikanth Shankar, Vikram Shukla,
Mike Stewart, Sankar Subramanian, Seema Sundara, Hal Takahara, Ashish Thusoo, Anh-Tuan Tran,
Randy Urbano, Guhan Viswanathan, David Wang, Jim Warner, Andy Witkowski, Daniel Wong, Jianping
Yang, Adiel Yoaz, Qin Yu, Tim Yu, Mohamed Zait, Fred Zemke
The Programs (which include both the software and documentation) contain proprietary information of
Oracle Corporation; they are provided under a license agreement containing restrictions on use and
disclosure and are also protected by copyright, patent and other intellectual and industrial property
laws. Reverse engineering, disassembly or decompilation of the Programs, except to the extent required
to obtain interoperability with other independently created software or as specified by law, is prohibited.
The information contained in this document is subject to change without notice. If you find any problems
in the documentation, please report them to us in writing. Oracle Corporation does not warrant that this
document is error-free. Except as may be expressly permitted in your license agreement for these
Programs, no part of these Programs may be reproduced or transmitted in any form or by any means,
electronic or mechanical, for any purpose, without the express written permission of Oracle Corporation.
If the Programs are delivered to the U.S. Government or anyone licensing or using the programs on
behalf of the U.S. Government, the following notice is applicable:
Restricted Rights Notice Programs delivered subject to the DOD FAR Supplement are "commercial
computer software" and use, duplication, and disclosure of the Programs, including documentation,
shall be subject to the licensing restrictions set forth in the applicable Oracle license agreement.
Otherwise, Programs delivered subject to the Federal Acquisition Regulations are "restricted computer
software" and use, duplication, and disclosure of the Programs shall be subject to the restrictions in FAR
52.227-19, Commercial Computer Software - Restricted Rights (June, 1987). Oracle Corporation, 500
Oracle Parkway, Redwood City, CA 94065.
The Programs are not intended for use in any nuclear, aviation, mass transit, medical, or other inherently
dangerous applications. It shall be the licensee's responsibility to take all appropriate fail-safe, backup,
redundancy, and other measures to ensure the safe use of such applications if the Programs are used for
such purposes, and Oracle Corporation disclaims liability for any damages caused by such use of the
Programs.
Oracle is a registered trademark, and Oracle7, Oracle8, Oracle8i, Oracle9i, Oracle Store, PL/SQL,
Pro*Ada, Pro*C, Pro*C/C++, Pro*COBOL, Pro*FORTRAN, Pro*Pascal, Pro*PL/1, and SQL*Plus are
trademarks or registered trademarks of Oracle Corporation. Other names may be trademarks of their
respective owners.
iii
Contents
Send Us Your Comments.................................................................................................................. xv
Preface......................................................................................................................................................... xvii
What’s New in SQL Reference?................................................................................................. xxvii
1 Introduction to Oracle SQL
2 Basic Elements of Oracle SQL
Datatypes ............................................................................................................................................. 2-2
Literals ................................................................................................................................................ 2-53
Format Models .................................................................................................................................. 2-61
Nulls ................................................................................................................................................... 2-80
Pseudocolumns ................................................................................................................................ 2-82
Comments .......................................................................................................................................... 2-90
Database Objects ............................................................................................................................ 2-106
Schema Object Names and Qualifiers........................................................................................ 2-110
Syntax for Schema Objects and Parts in SQL Statements...................................................... 2-115
3 Operators
About SQL Operators ........................................................................................................................ 3-2
Arithmetic Operators ........................................................................................................................ 3-3
Concatenation Operator .................................................................................................................... 3-4
Set Operators ...................................................................................................................................... 3-6
User-Defined Operators .................................................................................................................... 3-6
iv
4 Expressions
About SQL Expressions .................................................................................................................... 4-2
Simple Expressions ............................................................................................................................ 4-3
Compound Expressions .................................................................................................................... 4-5
CASE Expressions .............................................................................................................................. 4-6
CURSOR Expressions........................................................................................................................ 4-7
Datetime Expressions ........................................................................................................................ 4-9
Function Expressions ....................................................................................................................... 4-11
INTERVAL Expressions .................................................................................................................. 4-11
Object Access Expressions ............................................................................................................. 4-12
Scalar Subquery Expressions ......................................................................................................... 4-13
Type Constructor Expressions ....................................................................................................... 4-13
Variable Expressions ....................................................................................................................... 4-15
Expression Lists ................................................................................................................................ 4-16
5 Conditions
About SQL Conditions ...................................................................................................................... 5-2
Comparison Conditions .................................................................................................................... 5-4
Logical Conditions.............................................................................................................................. 5-8
Membership Conditions ................................................................................................................... 5-9
Range Conditions ............................................................................................................................. 5-12
Null Conditions ................................................................................................................................ 5-13
EQUALS_PATH ................................................................................................................................ 5-13
EXISTS Conditions .......................................................................................................................... 5-14
LIKE Conditions ............................................................................................................................... 5-15
IS OF type Conditions ..................................................................................................................... 5-19
UNDER_PATH .................................................................................................................................. 5-20
Compound Conditions ................................................................................................................... 5-21
6 Functions
SQL Functions .................................................................................................................................... 6-2
ABS ..................................................................................................................................................... 6-17
ACOS .................................................................................................................................................. 6-17
ADD_MONTHS ............................................................................................................................... 6-18
ASCII .................................................................................................................................................. 6-18
v
ASCIISTR .......................................................................................................................................... 6-19
ASIN ................................................................................................................................................... 6-20
ATAN .................................................................................................................................................. 6-21
ATAN2 ................................................................................................................................................ 6-21
AV G .................................................................................................................................................... 6-22
BFILENAME ..................................................................................................................................... 6-23
BIN_TO_NUM ................................................................................................................................. 6-25
BITAND ............................................................................................................................................. 6-25
CAST .................................................................................................................................................. 6-27
CEIL .................................................................................................................................................... 6-30
CHARTOROWID ............................................................................................................................ 6-30
CHR .................................................................................................................................................... 6-31
COALESCE ....................................................................................................................................... 6-33
COMPOSE ........................................................................................................................................ 6-34
CONCAT ........................................................................................................................................... 6-35
CONVERT ......................................................................................................................................... 6-36
CORR ................................................................................................................................................. 6-37
COS ..................................................................................................................................................... 6-39
COSH ................................................................................................................................................. 6-40
COUNT .............................................................................................................................................. 6-40
COVAR_POP .................................................................................................................................... 6-42
COVAR_SAMP ................................................................................................................................ 6-44
CUME_DIST ..................................................................................................................................... 6-47
CURRENT_DATE ............................................................................................................................ 6-49
CURRENT_TIMESTAMP .............................................................................................................. 6-50
DBTIMEZONE ................................................................................................................................. 6-51
DECODE ............................................................................................................................................ 6-52
DECOMPOSE ................................................................................................................................... 6-53
DENSE_RANK ................................................................................................................................. 6-55
DEPTH................................................................................................................................................ 6-57
DEREF ................................................................................................................................................ 6-58
DUMP ................................................................................................................................................ 6-59
EMPTY_BLOB, EMPTY_CLOB .................................................................................................... 6-61
EXISTSNODE ................................................................................................................................... 6-61
EXP ...................................................................................................................................................... 6-62