Oracle9 i SQL Reference Release 2 (9.2) March 2002 Part No. A96540-01 Oracle9i SQL Reference, Release 2 (9.2) Part No. A96540-01 Copyright © 1996, 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 xvii Preface xix What’s New in SQL Reference? xxix 1 Introduction 2 Basic Elements of Oracle SQL Datatypes 2-2 Literals 2-54 Format Models 2-62 Nulls 2-81 Pseudocolumns 2-83 Comments 2-90 Database Objects 2-107 Schema Object Names and Qualifiers 2-111 Syntax for Schema Objects and Parts in SQL Statements 2-116 3 Operators About SQL Operators 3-2 Arithmetic Operators 3-3 Concatenation Operator 3-4 Set Operators 3-6 iv User-Defined Operators 3-6 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-15 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-16 v ACOS 6-16 ADD_MONTHS 6-17 ASCII 6-17 ASCIISTR 6-18 ASIN 6-19 ATAN 6-20 ATAN2 6-20 AV G 6-21 BFILENAME 6-22 BIN_TO_NUM 6-23 BITAND 6-24 CAST 6-25 CEIL 6-28 CHARTOROWID 6-29 CHR 6-29 COALESCE 6-31 COMPOSE 6-32 CONCAT 6-33 CONVERT 6-34 CORR 6-35 COS 6-37 COSH 6-38 COUNT 6-38 COVAR_POP 6-40 COVAR_SAMP 6-42 CUME_DIST 6-45 CURRENT_DATE 6-47 CURRENT_TIMESTAMP 6-48 DBTIMEZONE 6-49 DECODE 6-50 DECOMPOSE 6-51 DENSE_RANK 6-53 DEPTH 6-55 DEREF 6-56 DUMP 6-57 vi EMPTY_BLOB, EMPTY_CLOB 6-59 EXISTSNODE 6-59 EXP 6-60 EXTRACT (datetime) 6-61 EXTRACT (XML) 6-62 EXTRACTVALUE 6-63 FIRST 6-64 FIRST_VALUE 6-66 FLOOR 6-68 FROM_TZ 6-68 GREATEST 6-69 GROUP_ID 6-69 GROUPING 6-71 GROUPING_ID 6-72 HEXTORAW 6-74 INITCAP 6-74 INSTR 6-75 LAG 6-77 LAST 6-78 LAST_DAY 6-80 LAST_VALUE 6-81 LEAD 6-83 LEAST 6-84 LENGTH 6-85 LN 6-86 LOCALTIMESTAMP 6-87 LOG 6-88 LOWER 6-88 LPAD 6-89 LTRIM 6-90 MAKE_REF 6-91 MAX 6-92 MIN 6-94 MOD 6-95 MONTHS_BETWEEN 6-96 vii NCHR 6-97 NEW_TIME 6-97 NEXT_DAY 6-99 NLS_CHARSET_DECL_LEN 6-99 NLS_CHARSET_ID 6-100 NLS_CHARSET_NAME 6-101 NLS_INITCAP 6-101 NLS_LOWER 6-103 NLSSORT 6-104 NLS_UPPER 6-105 NTILE 6-106 NULLIF 6-107 NUMTODSINTERVAL 6-108 NUMTOYMINTERVAL 6-109 NVL 6-110 NVL2 6-111 PATH 6-112 PERCENT_RANK 6-113 PERCENTILE_CONT 6-115 PERCENTILE_DISC 6-118 POWER 6-119 RANK 6-120 RATIO_TO_REPORT 6-122 RAWTOHEX 6-123 RAWTONHEX 6-123 REF 6-124 REFTOHEX 6-125 REGR_ (Linear Regression) Functions 6-126 REPLACE 6-134 ROUND (number) 6-135 ROUND (date) 6-136 ROW_NUMBER 6-136 ROWIDTOCHAR 6-138 ROWIDTONCHAR 6-138 RPAD 6-139 viii RTRIM 6-140 SESSIONTIMEZONE 6-140 SIGN 6-141 SIN 6-142 SINH 6-142 SOUNDEX 6-143 SQRT 6-144 STDDEV 6-145 STDDEV_POP 6-146 STDDEV_SAMP 6-148 SUBSTR 6-149 SUM 6-151 SYS_CONNECT_BY_PATH 6-152 SYS_CONTEXT 6-153 SYS_DBURIGEN 6-158 SYS_EXTRACT_UTC 6-159 SYS_GUID 6-160 SYS_TYPEID 6-161 SYS_XMLAGG 6-162 SYS_XMLGEN 6-163 SYSDATE 6-164 SYSTIMESTAMP 6-165 TAN 6-166 TANH 6-166 TO_CHAR (character) 6-167 TO_CHAR (datetime) 6-168 TO_CHAR (number) 6-170 TO_CLOB 6-172 TO_DATE 6-172 TO_DSINTERVAL 6-174 TO_LOB 6-175 TO_MULTI_BYTE 6-176 TO_NCHAR (character) 6-177 TO_NCHAR (datetime) 6-178 TO_NCHAR (number) 6-179 ix TO_NCLOB 6-180 TO_NUMBER 6-180 TO_SINGLE_BYTE 6-181 TO_TIMESTAMP 6-182 TO_TIMESTAMP_TZ 6-183 TO_YMINTERVAL 6-185 TRANSLATE 6-185 TRANSLATE USING 6-187 TREAT 6-188 TRIM 6-190 TRUNC (number) 6-191 TRUNC (date) 6-192 TZ_OFFSET 6-192 UID 6-193 UNISTR 6-194 UPDATEXML 6-194 UPPER 6-196 USER 6-196 USERENV 6-197 VALUE 6-199 VAR_POP 6-199 VAR_SAMP 6-201 VARIANCE 6-203 VSIZE 6-204 WIDTH_BUCKET 6-205 XMLAGG 6-207 XMLCOLATTVAL 6-208 XMLCONCAT 6-209 XMLELEMENT 6-211 XMLFOREST 6-214 XMLSEQUENCE 6-215 XMLTRANSFORM 6-216 ROUND and TRUNC Date Functions 6-218 User-Defined Functions 6-219 x 7 Common SQL DDL Clauses allocate_extent_clause 7-2 constraints 7-5 deallocate_unused_clause 7-37 file_specification 7-39 logging_clause 7-45 parallel_clause 7-49 physical_attributes_clause 7-52 storage_clause 7-56 8 SQL Queries and Subqueries About Queries and Subqueries 8-2 Creating Simple Queries 8-2 Hierarchical Queries 8-3 The UNION [ALL], INTERSECT, MINUS Operators 8-6 Sorting Query Results 8-9 Joins 8-9 Using Subqueries 8-13 Unnesting of Nested Subqueries 8-14 Selecting from the DUAL Table 8-15 Distributed Queries 8-15 9 SQL Statements: ALTER CLUSTER to ALTER SEQUENCE Types of SQL Statements 9-2 Organization of SQL Statements 9-5 ALTER CLUSTER 9-7 ALTER DATABASE 9-13 ALTER DIMENSION 9-58 ALTER FUNCTION 9-61 ALTER INDEX 9-64 ALTER INDEXTYPE 9-87 ALTER JAVA 9-89 ALTER MATERIALIZED VIEW 9-92 ALTER MATERIALIZED VIEW LOG 9-112 [...]... What’s New in SQL Reference? This section describes new features of Oracle9i release 2 and provides pointers to additional information New features information from previous releases is also retained to help those users upgrading to the current release The following sections describe the new features in Oracle SQL Reference: s Oracle9i Release 2 (9 .2) New Features in the SQL Reference s Oracle9i Release... 11 -2 ALTER TABLESPACE 11-101 12 SQL Statements: ALTER TRIGGER to COMMIT ALTER TRIGGER ALTER TYPE ALTER USER ALTER VIEW ANALYZE ASSOCIATE STATISTICS AUDIT CALL COMMENT COMMIT 12- 2 12- 6 12- 21 12- 30 12- 33 12- 48 12- 52 12- 66 12- 69... Reference s Oracle9i Release 1 (9.0.1) New Features in the SQL Reference s Oracle8i New Features in SQL Reference xxix Oracle9i Release 2 (9 .2) New Features in the SQL Reference The following built-in conditions are new to this release: s EQUALS_PATH on page 5-13 s UNDER_PATH on page 5 -20 The following built-in expression is enhanced in this release: s The syntax for type constructor expressions now... ALTER SEQUENCE 10 SQL Statements: ALTER SESSION to ALTER SYSTEM ALTER SESSION Initialization Parameters and ALTER SESSION Session Parameters and ALTER SESSION ALTER SYSTEM Initialization Parameters and ALTER SYSTEM 11 9-119 9- 120 9- 122 9- 126 9- 129 9-133 9-136 9-138 9-1 42 10 -2 10-8 10- 12 10 -22 10-36 SQL Statements: ALTER TABLE to... Oracle9i SQL Reference is intended for all users of Oracle SQL Organization This reference is divided into the following parts: Volume 1 Chapter 1, "Introduction" This chapter discusses the history of SQL and describes the advantages of using it to access relational databases Chapter 2, "Basic Elements of Oracle SQL" This chapter describes the basic building blocks of an Oracle database and of Oracle SQL. .. different types of SQL queries and lists the various types of SQL statements xx Volume 2 Chapter 9, "SQL Statements: ALTER CLUSTER to ALTER SEQUENCE" Chapter 10, "SQL Statements: ALTER SESSION to ALTER SYSTEM" Chapter 11, "SQL Statements: ALTER TABLE to ALTER TABLESPACE" Chapter 12, "SQL Statements: ALTER TRIGGER to COMMIT" Chapter 13, "SQL Statements: CREATE CLUSTER to CREATE JAVA" Chapter 14, "SQL Statements:... built-in functions are new to this release: s DEPTH on page 6-55 s EXTRACTVALUE on page 6-63 s PATH on page 6-1 12 s UPDATEXML on page 6-194 s XMLAGG on page 6 -20 7 s XMLCONCAT on page 6 -20 9 s XMLCOLATTVAL on page 6 -20 8 s XMLELEMENT on page 6 -21 1 s XMLFOREST on page 6 -21 4 s XMLSEQUENCE on page 6 -21 5 s XMLTRANSFORM on page 6 -21 6 The following privileges are new or enhanced in this release: s DEBUG CONNECT SESSION... the SQL Reference in Oracle9i Release 2 (9 .2) The following frequently used DDL clauses have been separated into their own chapter, Chapter 7, "Common SQL DDL Clauses": allocate_extent_clause on page 7 -2, constraints on page 7-5, deallocate_unused_clause on page 7-37, file_specification on page 7-39, logging_clause on page 7-45, parallel_clause on page 7-49, physical_attributes_clause on page 7- 52, ... 18-54 UPDATE 18-59 A How to Read Syntax Diagrams B Oracle and Standard SQL C Oracle Reserved Words D Examples Using Extensible Indexing D -2 xiv Using XML in SQL Statements D-11 Index xv xvi Send Us Your Comments Oracle9i SQL Reference, Release 2 (9 .2) Part No A96540-01 Oracle Corporation welcomes your comments and suggestions on the quality and... NOAUDIT on page 17- 82 Related Documentation For more information, see these Oracle resources: s s PL /SQL User’s Guide and Reference for information on PL /SQL, Oracle’s procedural language extension to SQL Pro*C/C++ Precompiler Programmer’s Guide, SQL* Module for Ada Programmer’s Guide, and the Pro*COBOL Precompiler Programmer’s Guide for detailed descriptions of Oracle embedded SQL Many of the examples . Oracle9 i SQL Reference Release 2 (9 .2) March 20 02 Part No. A96540-01 Oracle9i SQL Reference, Release 2 (9 .2) Part No. A96540-01 Copyright © 1996, 20 02, Oracle Corporation. All. Comments xvii Preface xix What’s New in SQL Reference? xxix 1 Introduction 2 Basic Elements of Oracle SQL Datatypes 2- 2 Literals 2- 54 Format Models 2- 62 Nulls 2- 81 Pseudocolumns 2- 83 Comments 2- 90 Database. 6-17 ASCIISTR 6-18 ASIN 6-19 ATAN 6 -20 ATAN2 6 -20 AV G 6 -21 BFILENAME 6 -22 BIN_TO_NUM 6 -23 BITAND 6 -24 CAST 6 -25 CEIL 6 -28 CHARTOROWID 6 -29 CHR 6 -29 COALESCE 6-31 COMPOSE 6- 32 CONCAT 6-33 CONVERT 6-34 CORR