Your SlideShare is downloading. ×
Oracle 10 g Good one
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Oracle 10 g Good one

216
views

Published on

Oracle 10 G

Oracle 10 G

Published in: Education

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
216
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Oracle® Database SQL Reference 10g Release 2 (10.2) B14200-02 December 2005
  • 2. Oracle Database SQL Reference, 10g Release 2 (10.2) B14200-02 Copyright © 1996, 2005 Oracle. All rights reserved. Primary Author: Diana Lorentz Contributor: Special thanks to Lex de Haan, who has for over ten years been a great source of information and inspiration in the management of this book. Contributors: Sundeep Abraham, Drew Adams, Patrick Amor, Geeta Arora, Lance Ashdown, Hermann Baer, Vladimir Barriere, Subhransu Basu, Mark Bauer, Tammy Bednar, Eric Belden, Tolga Bozkaya, Bill Bridge, Allen Brumm, Mark Callaghan, Thomas Chang, Timothy Chien, Dinesh Das, Jay Davison, Steve Fogel, Amit Ganesh, John Haydu, Min-Hank Ho, Lilian Hobbs, Chandrasekharan Iyer, Ken Jacobs, Bob Jenkins, Ramkumar Krishnan, Muralidhar Krishnaprasad, Joydip Kundu, Paul Lane, Simon Law, Bill Lee, Geoff Lee, Jeff Levinger, Nina Lewis, Brian Lin, Peter Linsley, Zhen Liu, Bryn Llewellyn, Rich Long, Qianrong Ma, Anand Manikutty, Paul Manning, Robert McGuirk, Jim Melton, Mughees Minhas, Michael Möller, Daniel Morgan, Ari Mozes, Niloy Mukherjee, Chuck Murray, Sujatha Muthulingam, Ananth Raghavan, Kathy Rich, Antonio Romero, John Russell, Vivian Schupmann, Cathy Shea, Vikram Shukla, Bipul Sinha, Mike Stewart, Sankar Subramanian, Srividya Tata, Kathy Taylor, Barry Trute, Randy Urbano, Rama Vissapragada, Douglas Voss, Daniel Wong, Jianping Yang, Adiel Yoaz, Qin Yu, Tsae-Feng Yu, Fred Zemke, Weiran Zhang The Programs (which include both the software and documentation) contain proprietary information; 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. This document is not warranted to be 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. If the Programs are delivered to the United States Government or anyone licensing or using the Programs on behalf of the United States Government, the following notice is applicable: U.S. GOVERNMENT RIGHTS Programs, software, databases, and related documentation and technical data delivered to U.S. Government customers are "commercial computer software" or "commercial technical data" pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such, use, duplication, disclosure, modification, and adaptation of the Programs, including documentation and technical data, shall be subject to the licensing restrictions set forth in the applicable Oracle license agreement, and, to the extent applicable, the additional rights set forth 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 we disclaim liability for any damages caused by such use of the Programs. Oracle, JD Edwards, PeopleSoft, and Retek are registered trademarks of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. The Programs may provide links to Web sites and access to content, products, and services from third parties. Oracle is not responsible for the availability of, or any content provided on, third-party Web sites. You bear all risks associated with the use of such content. If you choose to purchase any products or services from a third party, the relationship is directly between you and the third party. Oracle is not responsible for: (a) the quality of third-party products or services; or (b) fulfilling any of the terms of the agreement with the third party, including delivery of products or services and warranty obligations related to purchased products or services. Oracle is not responsible for any loss or damage of any sort that you may incur from dealing with any third party.
  • 3. iii Contents Preface............................................................................................................................................................... xxi Intended Audience.................................................................................................................................... xxi Documentation Accessibility................................................................................................................... xxi Related Documents .................................................................................................................................. xxii Conventions .............................................................................................................................................. xxii What's New in the SQL Reference?............................................................................................... xxiii Oracle Database 10g Release 2 New Features in the SQL Reference............................................... xxiii Oracle Database 10g Release 1 New Features in the SQL Reference............................................... xxv 1 Introduction to Oracle SQL History of SQL ......................................................................................................................................... 1-1 SQL Standards ......................................................................................................................................... 1-1 How SQL Works ............................................................................................................................... 1-2 Common Language for All Relational Databases ......................................................................... 1-3 Recent Enhancements.............................................................................................................................. 1-3 Lexical Conventions................................................................................................................................. 1-3 Tools Support ........................................................................................................................................... 1-4 2 Basic Elements of Oracle SQL Datatypes .................................................................................................................................................. 2-1 Oracle Built-in Datatypes.................................................................................................................. 2-6 CHAR Datatype ......................................................................................................................... 2-8 NCHAR Datatype ...................................................................................................................... 2-9 NVARCHAR2 Datatype ........................................................................................................... 2-9 VARCHAR2 Datatype ............................................................................................................... 2-9 VARCHAR Datatype .............................................................................................................. 2-10 NUMBER Datatype ................................................................................................................ 2-10 Floating-Point Numbers ........................................................................................................ 2-11 BINARY_FLOAT .............................................................................................................. 2-12 BINARY_DOUBLE........................................................................................................... 2-12 Numeric Precedence ............................................................................................................... 2-13 DATE Datatype ....................................................................................................................... 2-16 Using Julian Days ............................................................................................................. 2-16 TIMESTAMP Datatype .......................................................................................................... 2-17
  • 4. iv TIMESTAMP WITH TIME ZONE Datatype ....................................................................... 2-17 TIMESTAMP WITH LOCAL TIME ZONE Datatype ........................................................ 2-18 INTERVAL YEAR TO MONTH Datatype .......................................................................... 2-18 INTERVAL DAY TO SECOND Datatype ........................................................................... 2-19 Datetime/Interval Arithmetic ............................................................................................... 2-19 Support for Daylight Saving Times ...................................................................................... 2-21 Datetime and Interval Examples ........................................................................................... 2-22 RAW and LONG RAW Datatypes ....................................................................................... 2-23 BFILE Datatype ....................................................................................................................... 2-26 BLOB Datatype ........................................................................................................................ 2-26 CLOB Datatype ....................................................................................................................... 2-27 NCLOB Datatype .................................................................................................................... 2-27 Restricted Rowids ................................................................................................................... 2-27 Extended Rowids .................................................................................................................... 2-28 Compatibility and Migration ................................................................................................ 2-28 UROWID Datatype ................................................................................................................. 2-28 ANSI, DB2, and SQL/DS Datatypes ........................................................................................... 2-29 User-Defined Types ....................................................................................................................... 2-30 Object Types ............................................................................................................................ 2-30 REF Datatypes ......................................................................................................................... 2-31 Varrays ...................................................................................................................................... 2-31 Nested Tables .......................................................................................................................... 2-31 Oracle-Supplied Types .................................................................................................................. 2-32 Any Types ....................................................................................................................................... 2-32 ANYTYPE ................................................................................................................................. 2-32 ANYDATA................................................................................................................................ 2-32 ANYDATASET......................................................................................................................... 2-32 XML Types ...................................................................................................................................... 2-33 XMLType .................................................................................................................................. 2-33 URI Datatypes ......................................................................................................................... 2-33 URIFactory Package ................................................................................................................ 2-34 Spatial Types ................................................................................................................................... 2-34 SDO_GEOMETRY ................................................................................................................... 2-35 SDO_TOPO_GEOMETRY ..................................................................................................... 2-35 SDO_GEORASTER.................................................................................................................. 2-35 Media Types .................................................................................................................................... 2-35 ORDAudio ............................................................................................................................... 2-36 ORDImage ................................................................................................................................ 2-36 ORDImageSignature ............................................................................................................... 2-36 ORDVideo ................................................................................................................................ 2-36 ORDDoc .................................................................................................................................... 2-36 SI_StillImage ............................................................................................................................ 2-36 SI_Color .................................................................................................................................... 2-36 SI_AverageColor ..................................................................................................................... 2-36 SI_ColorHistogram ................................................................................................................. 2-36 SI_PositionalColor .................................................................................................................. 2-36 SI_Texture ................................................................................................................................ 2-36
  • 5. v SI_FeatureList .......................................................................................................................... 2-37 Expression Filter Type.................................................................................................................... 2-37 Expression................................................................................................................................. 2-37 Datatype Comparison Rules .............................................................................................................. 2-37 Numeric Values .............................................................................................................................. 2-37 Date Values ..................................................................................................................................... 2-37 Character Values ............................................................................................................................ 2-37 Object Values .................................................................................................................................. 2-40 Varrays and Nested Tables ........................................................................................................... 2-40 Data Conversion ............................................................................................................................. 2-40 Implicit and Explicit Data Conversion ................................................................................ 2-40 Implicit Data Conversion ....................................................................................................... 2-41 Implicit Data Conversion Examples...................................................................................... 2-43 Explicit Data Conversion ....................................................................................................... 2-43 Literals .................................................................................................................................................... 2-44 Text Literals ..................................................................................................................................... 2-45 Numeric Literals ............................................................................................................................. 2-46 Integer Literals ......................................................................................................................... 2-46 NUMBER and Floating-Point Literals .................................................................................. 2-47 Datetime Literals ............................................................................................................................ 2-49 Interval Literals................................................................................................................................ 2-51 INTERVAL YEAR TO MONTH ............................................................................................ 2-52 INTERVAL DAY TO SECOND ............................................................................................. 2-53 Format Models ...................................................................................................................................... 2-54 Number Format Models ................................................................................................................ 2-55 Number Format Elements ..................................................................................................... 2-56 Datetime Format Models .............................................................................................................. 2-58 Datetime Format Elements .................................................................................................... 2-59 Uppercase Letters in Date Format Elements ............................................................... 2-59 Punctuation and Character Literals in Datetime Format Models ............................. 2-59 Datetime Format Elements and Globalization Support .................................................... 2-62 ISO Standard Date Format Elements ................................................................................... 2-62 The RR Datetime Format Element ........................................................................................ 2-63 RR Datetime Format Examples....................................................................................... 2-63 Datetime Format Element Suffixes ....................................................................................... 2-64 Format Model Modifiers ............................................................................................................... 2-64 Format Model Examples......................................................................................................... 2-65 String-to-Date Conversion Rules ................................................................................................. 2-67 XML Format Model ....................................................................................................................... 2-67 Nulls ........................................................................................................................................................ 2-68 Nulls in SQL Functions ................................................................................................................. 2-69 Nulls with Comparison Conditions ............................................................................................ 2-69 Nulls in Conditions ........................................................................................................................ 2-69 Comments .............................................................................................................................................. 2-70 Comments Within SQL Statements ............................................................................................. 2-70 Comments on Schema Objects ..................................................................................................... 2-71 Using Hints ..................................................................................................................................... 2-71
  • 6. vi Alphabetical Listing of Hints ........................................................................................................ 2-75 ALL_ROWS Hint .................................................................................................................... 2-75 APPEND Hint .......................................................................................................................... 2-75 CACHE Hint ............................................................................................................................ 2-76 CLUSTER Hint ........................................................................................................................ 2-76 CURSOR_SHARING_EXACT Hint ..................................................................................... 2-76 DRIVING_SITE Hint .............................................................................................................. 2-77 DYNAMIC_SAMPLING Hint ............................................................................................... 2-77 FACT Hint ................................................................................................................................ 2-78 FIRST_ROWS Hint .................................................................................................................. 2-78 FULL Hint ................................................................................................................................ 2-78 HASH Hint .............................................................................................................................. 2-79 INDEX Hint ............................................................................................................................. 2-79 INDEX_ASC Hint ................................................................................................................... 2-80 INDEX_COMBINE Hint ....................................................................................................... 2-80 INDEX_DESC Hint ................................................................................................................. 2-80 INDEX_FFS Hint ..................................................................................................................... 2-81 INDEX_JOIN Hint .................................................................................................................. 2-81 INDEX_SS Hint ....................................................................................................................... 2-81 INDEX_SS_ASC Hint ............................................................................................................. 2-82 INDEX_SS_DESC Hint ........................................................................................................... 2-82 LEADING Hint ........................................................................................................................ 2-83 MERGE Hint ............................................................................................................................ 2-83 MODEL_MIN_ANALYSIS Hint ........................................................................................... 2-83 NOAPPEND Hint ................................................................................................................... 2-84 NOCACHE Hint ..................................................................................................................... 2-84 NO_EXPAND Hint ................................................................................................................. 2-84 NO_FACT Hint ....................................................................................................................... 2-85 NO_INDEX Hint ..................................................................................................................... 2-85 NO_INDEX_FFS Hint ............................................................................................................ 2-85 NO_INDEX_SS Hint ............................................................................................................... 2-86 NO_MERGE Hint ................................................................................................................... 2-86 NO_PARALLEL Hint ............................................................................................................. 2-86 NOPARALLEL Hint................................................................................................................ 2-87 NO_PARALLEL_INDEX Hint .............................................................................................. 2-87 NOPARALLEL_INDEX Hint................................................................................................. 2-87 NO_PUSH_PRED Hint .......................................................................................................... 2-87 NO_PUSH_SUBQ Hint .......................................................................................................... 2-87 NO_PX_JOIN_FILTER Hint .................................................................................................. 2-88 NO_REWRITE Hint ................................................................................................................ 2-88 NOREWRITE Hint................................................................................................................... 2-88 NO_QUERY_TRANSFORMATION Hint ........................................................................... 2-88 NO_STAR_TRANSFORMATION Hint ............................................................................... 2-88 NO_UNNEST Hint ................................................................................................................. 2-88 NO_USE_HASH Hint ............................................................................................................ 2-89 NO_USE_MERGE Hint .......................................................................................................... 2-89 NO_USE_NL Hint .................................................................................................................. 2-89
  • 7. vii NO_XML_QUERY_REWRITE Hint...................................................................................... 2-89 ORDERED Hint ....................................................................................................................... 2-90 PARALLEL Hint ..................................................................................................................... 2-90 PARALLEL_INDEX Hint ...................................................................................................... 2-91 PQ_DISTRIBUTE Hint ........................................................................................................... 2-91 PUSH_PRED Hint ................................................................................................................... 2-92 PUSH_SUBQ Hint ................................................................................................................... 2-93 PX_JOIN_FILTER Hint ........................................................................................................... 2-93 QB_NAME Hint ...................................................................................................................... 2-93 REWRITE Hint ........................................................................................................................ 2-94 RULE Hint ................................................................................................................................ 2-94 STAR_TRANSFORMATION Hint ....................................................................................... 2-94 UNNEST Hint .......................................................................................................................... 2-95 USE_CONCAT Hint ............................................................................................................... 2-95 USE_HASH Hint ..................................................................................................................... 2-96 USE_MERGE Hint .................................................................................................................. 2-96 USE_NL Hint ........................................................................................................................... 2-96 USE_NL_WITH_INDEX Hint ............................................................................................... 2-97 Database Objects................................................................................................................................... 2-97 Schema Objects ............................................................................................................................... 2-97 Nonschema Objects ........................................................................................................................ 2-98 Schema Object Names and Qualifiers ............................................................................................. 2-98 Schema Object Naming Rules ...................................................................................................... 2-98 Schema Object Naming Examples ............................................................................................. 2-101 Schema Object Naming Guidelines ........................................................................................... 2-102 Syntax for Schema Objects and Parts in SQL Statements........................................................... 2-102 How Oracle Database Resolves Schema Object References ................................................... 2-103 Referring to Objects in Other Schemas ..................................................................................... 2-104 Referring to Objects in Remote Databases ................................................................................ 2-104 Creating Database Links ...................................................................................................... 2-104 Database Link Names .................................................................................................... 2-104 Username and Password............................................................................................... 2-105 Database Connect String................................................................................................ 2-105 Referring to Database Links ................................................................................................ 2-105 Referring to Partitioned Tables and Indexes ............................................................................ 2-106 Referring to Object Type Attributes and Methods................................................................... 2-107 3 Pseudocolumns Hierarchical Query Pseudocolumns .................................................................................................... 3-1 CONNECT_BY_ISCYCLE Pseudocolumn .................................................................................... 3-1 CONNECT_BY_ISLEAF Pseudocolumn ....................................................................................... 3-2 LEVEL Pseudocolumn ...................................................................................................................... 3-2 Sequence Pseudocolumns ..................................................................................................................... 3-3 Where to Use Sequence Values ....................................................................................................... 3-3 How to Use Sequence Values .......................................................................................................... 3-4 Version Query Pseudocolumns ............................................................................................................ 3-5 COLUMN_VALUE Pseudocolumn ...................................................................................................... 3-6
  • 8. viii OBJECT_ID Pseudocolumn .................................................................................................................. 3-7 OBJECT_VALUE Pseudocolumn .......................................................................................................... 3-7 ORA_ROWSCN Pseudocolumn ........................................................................................................... 3-8 ROWID Pseudocolumn .......................................................................................................................... 3-8 ROWNUM Pseudocolumn .................................................................................................................... 3-9 XMLDATA Pseudocolumn ................................................................................................................. 3-10 4 Operators About SQL Operators.............................................................................................................................. 4-1 Unary and Binary Operators ........................................................................................................... 4-2 Operator Precedence ......................................................................................................................... 4-2 Arithmetic Operators .............................................................................................................................. 4-3 Concatenation Operator.......................................................................................................................... 4-3 Hierarchical Query Operators................................................................................................................ 4-5 PRIOR ................................................................................................................................................. 4-5 CONNECT_BY_ROOT ..................................................................................................................... 4-5 Set Operators ............................................................................................................................................ 4-5 Multiset Operators .................................................................................................................................. 4-5 MULTISET EXCEPT ......................................................................................................................... 4-6 MULTISET INTERSECT .................................................................................................................. 4-7 MULTISET UNION .......................................................................................................................... 4-8 User-Defined Operators ......................................................................................................................... 4-9 5 Functions SQL Functions .......................................................................................................................................... 5-1 Single-Row Functions ....................................................................................................................... 5-3 Numeric Functions .................................................................................................................... 5-3 Character Functions Returning Character Values ................................................................ 5-3 NLS Character Functions .......................................................................................................... 5-4 Character Functions Returning Number Values ................................................................... 5-4 Datetime Functions .................................................................................................................... 5-4 General Comparison Functions ............................................................................................... 5-5 Conversion Functions ................................................................................................................ 5-5 Large Object Functions .............................................................................................................. 5-6 Collection Functions .................................................................................................................. 5-6 Hierarchical Function ................................................................................................................ 5-6 Data Mining Functions .............................................................................................................. 5-6 XML Functions ........................................................................................................................... 5-7 Encoding and Decoding Functions ......................................................................................... 5-7 NULL-Related Functions .......................................................................................................... 5-7 Environment and Identifier Functions ................................................................................... 5-8 Aggregate Functions ......................................................................................................................... 5-8 Analytic Functions ............................................................................................................................ 5-9 Object Reference Functions ........................................................................................................... 5-14 Model Functions ............................................................................................................................. 5-15 Alphabetical Listing of SQL Functions ........................................................................................ 5-15 ABS .......................................................................................................................................................... 5-15
  • 9. ix ACOS ...................................................................................................................................................... 5-16 ADD_MONTHS ................................................................................................................................... 5-16 APPENDCHILDXML .......................................................................................................................... 5-17 ASCIISTR .............................................................................................................................................. 5-18 ASCII ...................................................................................................................................................... 5-18 ASIN ....................................................................................................................................................... 5-19 ATAN ...................................................................................................................................................... 5-19 ATAN2 .................................................................................................................................................... 5-20 AVG ......................................................................................................................................................... 5-20 BFILENAME .......................................................................................................................................... 5-21 BIN_TO_NUM ...................................................................................................................................... 5-22 BITAND .................................................................................................................................................. 5-23 CARDINALITY .................................................................................................................................... 5-24 CAST ....................................................................................................................................................... 5-24 CEIL ......................................................................................................................................................... 5-27 CHARTOROWID ................................................................................................................................. 5-27 CHR ......................................................................................................................................................... 5-28 CLUSTER_ID ........................................................................................................................................ 5-29 CLUSTER_PROBABILITY ................................................................................................................. 5-30 CLUSTER_SET ..................................................................................................................................... 5-32 COALESCE ............................................................................................................................................ 5-34 COLLECT ............................................................................................................................................... 5-35 COMPOSE ............................................................................................................................................. 5-36 CONCAT ................................................................................................................................................ 5-36 CONVERT ............................................................................................................................................. 5-37 CORR ...................................................................................................................................................... 5-38 CORR_* .................................................................................................................................................. 5-39 CORR_S ........................................................................................................................................... 5-40 CORR_K .......................................................................................................................................... 5-41 COS ......................................................................................................................................................... 5-41 COSH ...................................................................................................................................................... 5-42 COUNT ................................................................................................................................................... 5-42 COVAR_POP ......................................................................................................................................... 5-44 COVAR_SAMP ..................................................................................................................................... 5-45 CUME_DIST ......................................................................................................................................... 5-46 CURRENT_DATE ................................................................................................................................ 5-47 CURRENT_TIMESTAMP ................................................................................................................... 5-48 CV............................................................................................................................................................. 5-49 DBTIMEZONE ..................................................................................................................................... 5-50 DECODE ................................................................................................................................................ 5-51 DECOMPOSE ....................................................................................................................................... 5-52 DELETEXML ......................................................................................................................................... 5-53 DENSE_RANK ..................................................................................................................................... 5-54 DEPTH .................................................................................................................................................... 5-55 DEREF ..................................................................................................................................................... 5-56 DUMP ..................................................................................................................................................... 5-57 EMPTY_BLOB, EMPTY_CLOB ......................................................................................................... 5-58
  • 10. x EXISTSNODE ....................................................................................................................................... 5-58 EXP .......................................................................................................................................................... 5-59 EXTRACT (datetime) ........................................................................................................................... 5-60 EXTRACT (XML) .................................................................................................................................. 5-62 EXTRACTVALUE ................................................................................................................................. 5-63 FEATURE_ID ........................................................................................................................................ 5-63 FEATURE_SET ...................................................................................................................................... 5-65 FEATURE_VALUE ................................................................................................................................ 5-67 FIRST ...................................................................................................................................................... 5-68 FIRST_VALUE ...................................................................................................................................... 5-70 FLOOR .................................................................................................................................................... 5-71 FROM_TZ .............................................................................................................................................. 5-71 GREATEST ............................................................................................................................................ 5-72 GROUP_ID ............................................................................................................................................ 5-72 GROUPING ........................................................................................................................................... 5-73 GROUPING_ID .................................................................................................................................... 5-74 HEXTORAW .......................................................................................................................................... 5-75 INITCAP ................................................................................................................................................ 5-76 INSERTCHILDXML ............................................................................................................................ 5-76 INSERTXMLBEFORE .......................................................................................................................... 5-78 INSTR ..................................................................................................................................................... 5-79 ITERATION_NUMBER ...................................................................................................................... 5-80 LAG ......................................................................................................................................................... 5-81 LAST ....................................................................................................................................................... 5-82 LAST_DAY ............................................................................................................................................. 5-83 LAST_VALUE ........................................................................................................................................ 5-83 LEAD ....................................................................................................................................................... 5-85 LEAST ..................................................................................................................................................... 5-86 LENGTH ................................................................................................................................................ 5-86 LN ............................................................................................................................................................ 5-87 LNNVL ................................................................................................................................................... 5-88 LOCALTIMESTAMP ........................................................................................................................... 5-89 LOG ......................................................................................................................................................... 5-90 LOWER ................................................................................................................................................... 5-90 LPAD........................................................................................................................................................ 5-91 LTRIM ..................................................................................................................................................... 5-91 MAKE_REF ............................................................................................................................................ 5-92 MAX ........................................................................................................................................................ 5-93 MEDIAN ................................................................................................................................................ 5-94 MIN ......................................................................................................................................................... 5-96 MOD ....................................................................................................................................................... 5-97 MONTHS_BETWEEN ......................................................................................................................... 5-98 NANVL ................................................................................................................................................... 5-98 NCHR ..................................................................................................................................................... 5-99 NEW_TIME ......................................................................................................................................... 5-100 NEXT_DAY .......................................................................................................................................... 5-101 NLS_CHARSET_DECL_LEN ........................................................................................................... 5-101
  • 11. xi NLS_CHARSET_ID ........................................................................................................................... 5-102 NLS_CHARSET_NAME ................................................................................................................... 5-102 NLS_INITCAP .................................................................................................................................... 5-103 NLS_LOWER ....................................................................................................................................... 5-104 NLSSORT ............................................................................................................................................. 5-104 NLS_UPPER ........................................................................................................................................ 5-106 NTILE ................................................................................................................................................... 5-106 NULLIF ................................................................................................................................................. 5-107 NUMTODSINTERVAL ..................................................................................................................... 5-108 NUMTOYMINTERVAL .................................................................................................................... 5-109 NVL ....................................................................................................................................................... 5-110 NVL2 ..................................................................................................................................................... 5-111 ORA_HASH ........................................................................................................................................ 5-112 PATH...................................................................................................................................................... 5-112 PERCENT_RANK .............................................................................................................................. 5-113 PERCENTILE_CONT ........................................................................................................................ 5-114 PERCENTILE_DISC .......................................................................................................................... 5-116 POWER ................................................................................................................................................. 5-118 POWERMULTISET ............................................................................................................................ 5-118 POWERMULTISET_BY_CARDINALITY ..................................................................................... 5-119 PREDICTION ..................................................................................................................................... 5-120 PREDICTION_COST ........................................................................................................................ 5-122 PREDICTION_DETAILS .................................................................................................................. 5-123 PREDICTION_PROBABILITY ....................................................................................................... 5-124 PREDICTION_SET ............................................................................................................................ 5-126 PRESENTNNV .................................................................................................................................... 5-128 PRESENTV ........................................................................................................................................... 5-129 PREVIOUS ........................................................................................................................................... 5-130 RANK ................................................................................................................................................... 5-131 RATIO_TO_REPORT ........................................................................................................................ 5-133 RAWTOHEX ........................................................................................................................................ 5-133 RAWTONHEX .................................................................................................................................... 5-134 REF ........................................................................................................................................................ 5-134 REFTOHEX .......................................................................................................................................... 5-135 REGEXP_INSTR ................................................................................................................................. 5-136 REGEXP_REPLACE ........................................................................................................................... 5-138 REGEXP_SUBSTR ............................................................................................................................. 5-140 REGR_ (Linear Regression) Functions ........................................................................................... 5-142 REMAINDER ...................................................................................................................................... 5-147 REPLACE ............................................................................................................................................. 5-148 ROUND (number) .............................................................................................................................. 5-148 ROUND (date) .................................................................................................................................... 5-149 ROW_NUMBER ................................................................................................................................. 5-150 ROWIDTOCHAR ............................................................................................................................... 5-151 ROWIDTONCHAR ........................................................................................................................... 5-151 RPAD .................................................................................................................................................... 5-152 RTRIM .................................................................................................................................................. 5-153
  • 12. xii SCN_TO_TIMESTAMP .................................................................................................................... 5-153 SESSIONTIMEZONE ....................................................................................................................... 5-154 SET ........................................................................................................................................................ 5-155 SIGN ..................................................................................................................................................... 5-155 SIN ......................................................................................................................................................... 5-156 SINH ..................................................................................................................................................... 5-156 SOUNDEX ........................................................................................................................................... 5-157 SQRT ..................................................................................................................................................... 5-158 STATS_BINOMIAL_TEST ............................................................................................................... 5-159 STATS_CROSSTAB ........................................................................................................................... 5-160 STATS_F_TEST ................................................................................................................................... 5-161 STATS_KS_TEST ................................................................................................................................ 5-162 STATS_MODE .................................................................................................................................... 5-162 STATS_MW_TEST ............................................................................................................................. 5-164 STATS_ONE_WAY_ANOVA ............................................................................................................ 5-165 STATS_T_TEST_* ............................................................................................................................... 5-166 STATS_T_TEST_ONE .................................................................................................................. 5-167 STATS_T_TEST_PAIRED ........................................................................................................... 5-167 STATS_T_TEST_INDEP and STATS_T_TEST_INDEPU ....................................................... 5-168 STATS_WSR_TEST ............................................................................................................................ 5-169 STDDEV ............................................................................................................................................... 5-170 STDDEV_POP .................................................................................................................................... 5-171 STDDEV_SAMP ................................................................................................................................. 5-172 SUBSTR ................................................................................................................................................ 5-173 SUM ...................................................................................................................................................... 5-174 SYS_CONNECT_BY_PATH ............................................................................................................. 5-176 SYS_CONTEXT .................................................................................................................................. 5-176 SYS_DBURIGEN ................................................................................................................................ 5-181 SYS_EXTRACT_UTC ........................................................................................................................ 5-182 SYS_GUID ........................................................................................................................................... 5-182 SYS_TYPEID ....................................................................................................................................... 5-183 SYS_XMLAGG ................................................................................................................................... 5-184 SYS_XMLGEN .................................................................................................................................... 5-185 SYSDATE ............................................................................................................................................. 5-185 SYSTIMESTAMP ............................................................................................................................... 5-186 TAN ....................................................................................................................................................... 5-186 TANH .................................................................................................................................................... 5-187 TIMESTAMP_TO_SCN .................................................................................................................... 5-187 TO_BINARY_DOUBLE ..................................................................................................................... 5-188 TO_BINARY_FLOAT ........................................................................................................................ 5-189 TO_CHAR (character) ........................................................................................................................ 5-190 TO_CHAR (datetime) ........................................................................................................................ 5-191 TO_CHAR (number) .......................................................................................................................... 5-193 TO_CLOB ............................................................................................................................................. 5-194 TO_DATE ............................................................................................................................................. 5-195 TO_DSINTERVAL ............................................................................................................................. 5-196 TO_LOB ............................................................................................................................................... 5-196
  • 13. xiii TO_MULTI_BYTE .............................................................................................................................. 5-197 TO_NCHAR (character) .................................................................................................................... 5-198 TO_NCHAR (datetime) ..................................................................................................................... 5-198 TO_NCHAR (number) ...................................................................................................................... 5-199 TO_NCLOB ......................................................................................................................................... 5-199 TO_NUMBER ..................................................................................................................................... 5-200 TO_SINGLE_BYTE ............................................................................................................................ 5-201 TO_TIMESTAMP ............................................................................................................................... 5-201 TO_TIMESTAMP_TZ ........................................................................................................................ 5-202 TO_YMINTERVAL ........................................................................................................................... 5-203 TRANSLATE ....................................................................................................................................... 5-203 TRANSLATE ... USING .................................................................................................................... 5-204 TREAT .................................................................................................................................................. 5-206 TRIM ..................................................................................................................................................... 5-207 TRUNC (number) ............................................................................................................................... 5-208 TRUNC (date) ...................................................................................................................................... 5-208 TZ_OFFSET ......................................................................................................................................... 5-209 UID ........................................................................................................................................................ 5-210 UNISTR ................................................................................................................................................ 5-210 UPDATEXML ...................................................................................................................................... 5-211 UPPER ................................................................................................................................................... 5-212 USER ..................................................................................................................................................... 5-212 USERENV ............................................................................................................................................ 5-213 VALUE .................................................................................................................................................. 5-214 VAR_POP ............................................................................................................................................. 5-214 VAR_SAMP ......................................................................................................................................... 5-216 VARIANCE .......................................................................................................................................... 5-216 VSIZE .................................................................................................................................................... 5-218 WIDTH_BUCKET .............................................................................................................................. 5-218 XMLAGG ............................................................................................................................................. 5-220 XMLCDATA ........................................................................................................................................ 5-221 XMLCOLATTVAL............................................................................................................................... 5-222 XMLCOMMENT ................................................................................................................................ 5-223 XMLCONCAT ..................................................................................................................................... 5-223 XMLELEMENT.................................................................................................................................... 5-224 XMLFOREST ....................................................................................................................................... 5-226 XMLPARSE .......................................................................................................................................... 5-227 XMLPI ................................................................................................................................................... 5-228 XMLQUERY ......................................................................................................................................... 5-228 XMLROOT ........................................................................................................................................... 5-230 XMLSEQUENCE ................................................................................................................................. 5-230 XMLSERIALIZE ................................................................................................................................. 5-232 XMLTABLE .......................................................................................................................................... 5-232 XMLTRANSFORM ............................................................................................................................. 5-234 ROUND and TRUNC Date Functions ............................................................................................ 5-235 User-Defined Functions .................................................................................................................... 5-236 Prerequisites................................................................................................................................... 5-237
  • 14. xiv Name Precedence ......................................................................................................................... 5-237 Naming Conventions ........................................................................................................... 5-238 6 Expressions About SQL Expressions ......................................................................................................................... 6-1 Simple Expressions ................................................................................................................................. 6-3 Compound Expressions ......................................................................................................................... 6-4 CASE Expressions ................................................................................................................................... 6-5 CURSOR Expressions.............................................................................................................................. 6-6 Datetime Expressions ............................................................................................................................. 6-8 Function Expressions .............................................................................................................................. 6-9 Interval Expressions ............................................................................................................................. 6-10 Object Access Expressions .................................................................................................................. 6-10 Scalar Subquery Expressions ............................................................................................................. 6-11 Model Expressions ................................................................................................................................ 6-11 Type Constructor Expressions ............................................................................................................ 6-13 Variable Expressions ............................................................................................................................ 6-15 Expression Lists .................................................................................................................................... 6-15 7 Conditions About SQL Conditions............................................................................................................................ 7-1 Condition Precedence........................................................................................................................ 7-3 Comparison Conditions ......................................................................................................................... 7-4 Simple Comparison Conditions ...................................................................................................... 7-5 Group Comparison Conditions ....................................................................................................... 7-6 Floating-Point Conditions ..................................................................................................................... 7-7 Logical Conditions ................................................................................................................................... 7-7 Model Conditions ................................................................................................................................... 7-9 IS ANY Condition ............................................................................................................................. 7-9 IS PRESENT Condition ................................................................................................................. 7-10 Multiset Conditions ............................................................................................................................. 7-11 IS A SET Condition ........................................................................................................................ 7-11 IS EMPTY Condition ...................................................................................................................... 7-11 MEMBER Condition ...................................................................................................................... 7-12 SUBMULTISET Condition ............................................................................................................ 7-13 Pattern-matching Conditions ............................................................................................................. 7-14 LIKE Condition ............................................................................................................................... 7-14 REGEXP_LIKE Condition ............................................................................................................. 7-17 Range Conditions ................................................................................................................................. 7-18 Null Conditions .................................................................................................................................... 7-19 XML Conditions ................................................................................................................................... 7-19 EQUALS_PATH Condition .......................................................................................................... 7-19 UNDER_PATH Condition ............................................................................................................ 7-20 Compound Conditions ........................................................................................................................ 7-21 EXISTS Condition ................................................................................................................................ 7-21 IN Condition ........................................................................................................................................ 7-21 IS OF type Condition ........................................................................................................................... 7-23
  • 15. xv 8 Common SQL DDL Clauses allocate_extent_clause ............................................................................................................................ 8-2 constraint .................................................................................................................................................. 8-4 deallocate_unused_clause .................................................................................................................... 8-26 file_specification ................................................................................................................................... 8-28 logging_clause ........................................................................................................................................ 8-36 parallel_clause ....................................................................................................................................... 8-39 physical_attributes_clause .................................................................................................................. 8-42 size_clause ............................................................................................................................................. 8-45 storage_clause ........................................................................................................................................ 8-46 9 SQL Queries and Subqueries About Queries and Subqueries ............................................................................................................ 9-1 Creating Simple Queries ........................................................................................................................ 9-2 Hierarchical Queries ............................................................................................................................... 9-2 Hierarchical Query Examples .......................................................................................................... 9-5 The UNION [ALL], INTERSECT, MINUS Operators....................................................................... 9-7 Sorting Query Results ............................................................................................................................ 9-9 Joins ......................................................................................................................................................... 9-10 Join Conditions ............................................................................................................................... 9-10 Equijoins .......................................................................................................................................... 9-10 Self Joins .......................................................................................................................................... 9-11 Cartesian Products ......................................................................................................................... 9-11 Inner Joins ....................................................................................................................................... 9-11 Outer Joins ....................................................................................................................................... 9-11 Antijoins .......................................................................................................................................... 9-13 Semijoins .......................................................................................................................................... 9-13 Using Subqueries ................................................................................................................................. 9-13 Unnesting of Nested Subqueries ...................................................................................................... 9-14 Selecting from the DUAL Table ........................................................................................................ 9-15 Distributed Queries ............................................................................................................................. 9-15 10 SQL Statements: ALTER CLUSTER to ALTER JAVA Types of SQL Statements .................................................................................................................... 10-1 Data Definition Language (DDL) Statements ............................................................................ 10-1 Data Manipulation Language (DML) Statements ..................................................................... 10-2 Transaction Control Statements ................................................................................................... 10-3 Session Control Statements ........................................................................................................... 10-3 System Control Statement ............................................................................................................. 10-3 Embedded SQL Statements .......................................................................................................... 10-3 How the SQL Statement Chapters are Organized ......................................................................... 10-3 ALTER CLUSTER ................................................................................................................................. 10-5 ALTER DATABASE ............................................................................................................................. 10-9 ALTER DIMENSION ........................................................................................................................ 10-45 ALTER DISKGROUP ........................................................................................................................ 10-48 ALTER FUNCTION ........................................................................................................................... 10-61
  • 16. xvi ALTER INDEX .................................................................................................................................... 10-64 ALTER INDEXTYPE .......................................................................................................................... 10-82 ALTER JAVA ........................................................................................................................................ 10-84 11 SQL Statements: ALTER MATERIALIZED VIEW to ALTER SYSTEM ALTER MATERIALIZED VIEW ........................................................................................................ 11-2 ALTER MATERIALIZED VIEW LOG ............................................................................................ 11-15 ALTER OPERATOR ........................................................................................................................... 11-21 ALTER OUTLINE ............................................................................................................................... 11-24 ALTER PACKAGE ............................................................................................................................. 11-26 ALTER PROCEDURE ........................................................................................................................ 11-29 ALTER PROFILE ................................................................................................................................ 11-32 ALTER RESOURCE COST ............................................................................................................... 11-35 ALTER ROLE ....................................................................................................................................... 11-38 ALTER ROLLBACK SEGMENT ..................................................................................................... 11-40 ALTER SEQUENCE ........................................................................................................................... 11-43 ALTER SESSION ................................................................................................................................ 11-45 Initialization Parameters and ALTER SESSION....................................................................... 11-50 Session Parameters and ALTER SESSION ............................................................................... 11-53 ALTER SYSTEM ................................................................................................................................. 11-60 Initialization Parameters and ALTER SYSTEM........................................................................ 11-72 System Parameters and ALTER SYSTEM.................................................................................. 11-83 Shared Server Parameters .................................................................................................... 11-83 12 SQL Statements: ALTER TABLE to ALTER TABLESPACE ALTER TABLE ....................................................................................................................................... 12-2 ALTER TABLESPACE ........................................................................................................................ 12-79 13 SQL Statements: ALTER TRIGGER to COMMIT ALTER TRIGGER ................................................................................................................................. 13-2 ALTER TYPE ......................................................................................................................................... 13-5 ALTER USER ....................................................................................................................................... 13-18 ALTER VIEW ....................................................................................................................................... 13-25 ANALYZE ............................................................................................................................................ 13-27 ASSOCIATE STATISTICS ................................................................................................................ 13-38 AUDIT .................................................................................................................................................. 13-42 CALL ..................................................................................................................................................... 13-53 COMMENT ......................................................................................................................................... 13-57 COMMIT ............................................................................................................................................. 13-59 14 SQL Statements: CREATE CLUSTER to CREATE JAVA CREATE CLUSTER .............................................................................................................................. 14-2 CREATE CONTEXT ............................................................................................................................. 14-9 CREATE CONTROLFILE ................................................................................................................. 14-12 CREATE DATABASE ......................................................................................................................... 14-18 CREATE DATABASE LINK ............................................................................................................. 14-31
  • 17. xvii CREATE DIMENSION ..................................................................................................................... 14-36 CREATE DIRECTORY ...................................................................................................................... 14-42 CREATE DISKGROUP ..................................................................................................................... 14-44 CREATE FUNCTION ........................................................................................................................ 14-48 CREATE INDEX ................................................................................................................................. 14-58 CREATE INDEXTYPE ....................................................................................................................... 14-81 CREATE JAVA ..................................................................................................................................... 14-84 15 SQL Statements: CREATE LIBRARY to CREATE SPFILE CREATE LIBRARY ............................................................................................................................... 15-2 CREATE MATERIALIZED VIEW ..................................................................................................... 15-4 CREATE MATERIALIZED VIEW LOG ......................................................................................... 15-25 CREATE OPERATOR ........................................................................................................................ 15-32 CREATE OUTLINE ............................................................................................................................ 15-35 CREATE PACKAGE ........................................................................................................................... 15-39 CREATE PACKAGE BODY .............................................................................................................. 15-43 CREATE PFILE .................................................................................................................................... 15-47 CREATE PROCEDURE ..................................................................................................................... 15-49 CREATE PROFILE ............................................................................................................................. 15-54 CREATE RESTORE POINT ............................................................................................................. 15-60 CREATE ROLE .................................................................................................................................... 15-63 CREATE ROLLBACK SEGMENT .................................................................................................. 15-66 CREATE SCHEMA ............................................................................................................................. 15-69 CREATE SEQUENCE ........................................................................................................................ 15-71 CREATE SPFILE ................................................................................................................................. 15-75 16 SQL Statements: CREATE SYNONYM to CREATE TRIGGER CREATE SYNONYM ........................................................................................................................... 16-2 CREATE TABLE .................................................................................................................................... 16-6 CREATE TABLESPACE ..................................................................................................................... 16-61 CREATE TRIGGER ............................................................................................................................ 16-75 17 SQL Statements: CREATE TYPE to DROP ROLLBACK SEGMENT CREATE TYPE ....................................................................................................................................... 17-3 CREATE TYPE BODY ........................................................................................................................ 17-21 CREATE USER .................................................................................................................................... 17-26 CREATE VIEW .................................................................................................................................... 17-32 DELETE ................................................................................................................................................ 17-43 DISASSOCIATE STATISTICS ........................................................................................................ 17-51 DROP CLUSTER ................................................................................................................................ 17-53 DROP CONTEXT ............................................................................................................................... 17-55 DROP DATABASE ............................................................................................................................. 17-56 DROP DATABASE LINK ................................................................................................................. 17-57 DROP DIMENSION .......................................................................................................................... 17-58 DROP DIRECTORY .......................................................................................................................... 17-59 DROP DISKGROUP ......................................................................................................................... 17-60
  • 18. xviii DROP FUNCTION ............................................................................................................................ 17-62 DROP INDEX....................................................................................................................................... 17-64 DROP INDEXTYPE ........................................................................................................................... 17-66 DROP JAVA ......................................................................................................................................... 17-67 DROP LIBRARY ................................................................................................................................. 17-68 DROP MATERIALIZED VIEW........................................................................................................ 17-69 DROP MATERIALIZED VIEW LOG ............................................................................................. 17-71 DROP OPERATOR ............................................................................................................................ 17-73 DROP OUTLINE ................................................................................................................................ 17-74 DROP PACKAGE ............................................................................................................................... 17-75 DROP PROCEDURE ......................................................................................................................... 17-77 DROP PROFILE .................................................................................................................................. 17-78 DROP RESTORE POINT ................................................................................................................. 17-79 DROP ROLE ........................................................................................................................................ 17-80 DROP ROLLBACK SEGMENT ...................................................................................................... 17-81 18 SQL Statements: DROP SEQUENCE to ROLLBACK DROP SEQUENCE .............................................................................................................................. 18-2 DROP SYNONYM ............................................................................................................................... 18-3 DROP TABLE ........................................................................................................................................ 18-5 DROP TABLESPACE ........................................................................................................................... 18-9 DROP TRIGGER................................................................................................................................. 18-12 DROP TYPE ......................................................................................................................................... 18-13 DROP TYPE BODY ............................................................................................................................ 18-15 DROP USER ........................................................................................................................................ 18-16 DROP VIEW ........................................................................................................................................ 18-18 EXPLAIN PLAN .................................................................................................................................. 18-20 FLASHBACK DATABASE ................................................................................................................ 18-23 FLASHBACK TABLE ......................................................................................................................... 18-26 GRANT ................................................................................................................................................. 18-32 INSERT ................................................................................................................................................. 18-51 LOCK TABLE ...................................................................................................................................... 18-68 MERGE ................................................................................................................................................. 18-71 NOAUDIT ............................................................................................................................................ 18-76 PURGE .................................................................................................................................................. 18-80 RENAME .............................................................................................................................................. 18-82 REVOKE ............................................................................................................................................... 18-84 ROLLBACK ......................................................................................................................................... 18-92 19 SQL Statements: SAVEPOINT to UPDATE SAVEPOINT .......................................................................................................................................... 19-2 SELECT ................................................................................................................................................... 19-4 SET CONSTRAINT[S] ...................................................................................................................... 19-48 SET ROLE ............................................................................................................................................ 19-50 SET TRANSACTION ........................................................................................................................ 19-52 TRUNCATE ......................................................................................................................................... 19-55
  • 19. xix UPDATE ............................................................................................................................................... 19-59 A How to Read Syntax Diagrams Graphic Syntax Diagrams...................................................................................................................... A-1 Required Keywords and Parameters ............................................................................................ A-2 Optional Keywords and Parameters ............................................................................................. A-3 Syntax Loops...................................................................................................................................... A-3 Multipart Diagrams ......................................................................................................................... A-4 Database Objects .............................................................................................................................. A-4 B Oracle and Standard SQL ANSI Standards ...................................................................................................................................... B-1 ISO Standards .......................................................................................................................................... B-2 Oracle Compliance To Core SQL:2003................................................................................................. B-3 Oracle Support for Optional Features of SQL/Foundation:2003.................................................... B-8 Oracle Compliance with SQL/CLI:2003 ............................................................................................ B-15 Oracle Compliance with SQL/PSM:2003 .......................................................................................... B-15 Oracle Compliance with SQL/MED:2003 ......................................................................................... B-15 Oracle Compliance with SQL/XML:2005.......................................................................................... B-16 Oracle Compliance with FIPS 127-2 ................................................................................................. B-22 Oracle Extensions to Standard SQL .................................................................................................. B-24 Character Set Support........................................................................................................................... B-24 C Oracle Regular Expression Support Multilingual Regular Expression Syntax .......................................................................................... C-1 Regular Expression Operator Multilingual Enhancements............................................................ C-2 Perl-influenced Extensions in Oracle Regular Expressions ........................................................... C-3 D Oracle Database Reserved Words E Examples Using Extensible Indexing ................................................................................................................... E-1 Using XML in SQL Statements ............................................................................................................ E-8 Index
  • 20. xx
  • 21. xxi Preface This reference contains a complete description of the Structured Query Language (SQL) used to manage information in an Oracle Database. Oracle SQL is a superset of the American National Standards Institute (ANSI) and the International Standards Organization (ISO) SQL:1999 standard. This Preface contains these topics: ■ Intended Audience ■ Documentation Accessibility ■ Related Documents ■ Conventions Intended Audience The Oracle Database SQL Reference is intended for all users of Oracle SQL. Documentation Accessibility Our goal is to make Oracle products, services, and supporting documentation accessible, with good usability, to the disabled community. To that end, our documentation includes features that make information available to users of assistive technology. This documentation is available in HTML format, and contains markup to facilitate access by the disabled community. Accessibility standards will continue to evolve over time, and Oracle is actively engaged with other market-leading technology vendors to address technical obstacles so that our documentation can be accessible to all of our customers. For more information, visit the Oracle Accessibility Program Web site at http://www.oracle.com/accessibility/ Accessibility of Code Examples in Documentation Screen readers may not always correctly read the code examples in this document. The conventions for writing code require that closing braces should appear on an otherwise empty line; however, some screen readers may not always read a line of text that consists solely of a bracket or brace. Accessibility of Links to External Web Sites in Documentation This documentation may contain links to Web sites of other companies or organizations that Oracle does not own or control. Oracle neither evaluates nor makes any representations regarding the accessibility of these Web sites.
  • 22. xxii TTY Access to Oracle Support Services Oracle provides dedicated Text Telephone (TTY) access to Oracle Support Services within the United States of America 24 hours a day, seven days a week. For TTY support, call 800.446.2398. Related Documents For more information, see these Oracle resources: ■ Oracle Database PL/SQL User's Guide and Reference for information on PL/SQL, the procedural language extension to Oracle SQL ■ Pro*C/C++ Programmer's Guide, Oracle SQL*Module for Ada Programmer's Guide, and the Pro*COBOL Programmer's Guide for detailed descriptions of Oracle embedded SQL Many of the examples in this book use the sample schemas, which are installed by default when you select the Basic Installation option with an Oracle Database installation. Refer to Oracle Database Sample Schemas for information on how these schemas were created and how you can use them yourself. Conventions The following text conventions are used in this document: Convention Meaning boldface Boldface type indicates graphical user interface elements associated with an action, or terms defined in text or the glossary. italic Italic type indicates book titles, emphasis, or placeholder variables for which you supply particular values. monospace Monospace type indicates commands within a paragraph, URLs, code in examples, text that appears on the screen, or text that you enter.
  • 23. xxiii What's New in the SQL Reference? This section describes new features of Oracle Database 10g and provides pointers to additional information. For information on features that were new in earlier versions of Oracle Database, please refer to the documentation for the earlier release. Oracle Database 10g Release 2 New Features in the SQL Reference The following top-level SQL statements are new or enhanced in this release: ■ ALTER DATABASE on page 10-9 has been enhanced as follows: – New syntax in the standby_database_clauses lets you bring a logical standby database to the same state as the primary database. – Additional new syntax in the standby_database_clauses lets you convert a primary database outside the Data Guard environment into a physical standby database. – New syntax in the managed_standby_recovery clause lets you create a logical standby database from the physical standby database. – New syntax in the database_file_clauses lets you rename tempfiles as well as datafiles and redo log files. ■ ALTER DISKGROUP on page 10-48 has new syntax that lets you specify when in the course of a diskgroup rebalance operation control should be returned to the user. ■ ALTER SYSTEM on page 11-60 has new syntax that lets you load information from the server wallet into memory for database access, and to generate a new transparent database encryption master key: ■ ALTER TABLESPACE on page 12-79 contains new syntax that lets you drop an empty datafile or tempfile from the data dictionary and remove it from the operating system. ■ ALTER USER on page 13-18 contains new syntax that lets you expose a user to proxy use by enterprise users. ■ COMMIT on page 13-59 contains a new WRITE clause that lets you specify the priority with which the redo information generated by the commit operation is written to the redo log. ■ CREATE DATABASE LINK on page 14-31 has new syntax that helps Data Pump provide an encoded password for the database link during import of data.
  • 24. xxiv ■ CREATE DIMENSION on page 14-36 and ALTER DIMENSION on page 10-45 contain new syntax that lets you preserve the hierarchical chain of parent-child relationship by an alternative path that skips over a specified level if it is null. ■ CREATE RESTORE POINT on page 15-60 is a new SQL statement that lets you create a restore point, to which you can flash back a table or the database. ■ CREATE TABLE on page 16-6 documents the new limit on number of partitions and subpartitions as 1024K - 1. ■ CREATE TABLE on page 16-6 and ALTER TABLE on page 12-2 contains new syntax that lets you encrypt column data. ■ CREATE USER on page 17-26 and ALTER USER on page 13-18 contain new syntax for determining how global and external users are identified. ■ DROP RESTORE POINT on page 17-79 is a new SQL statement that lets you drop a restore point. ■ FLASHBACK DATABASE on page 18-23 has new syntax that lets you flash back the database to a restore point. ■ FLASHBACK TABLE on page 18-26 has new syntax that lets you flash back a table to a restore point. The following clauses are modified in this release: ■ All of the DML statements (INSERT, UPDATE, DELETE, MERGE) now have an error logging clause. See for example INSERT on page 18-51. ■ "Model Expressions" on page 6-11 have been enhanced to allow analytic functions and FOR loops. The following built-in data mining functions are new in this release: ■ CLUSTER_ID on page 5-29 ■ CLUSTER_PROBABILITY on page 5-30 ■ CLUSTER_SET on page 5-32 ■ FEATURE_ID on page 5-63 ■ FEATURE_SET on page 5-65 ■ FEATURE_VALUE on page 5-67 ■ PREDICTION on page 5-120 ■ PREDICTION_COST on page 5-122 ■ PREDICTION_DETAILS on page 5-123 ■ PREDICTION_PROBABILITY on page 5-124 ■ PREDICTION_SET on page 5-126 The following built-in XML functions are new in this release: ■ APPENDCHILDXML ■ DELETEXML ■ INSERTCHILDXML ■ INSERTXMLBEFORE ■ XMLCDATA ■ XMLCOMMENT
  • 25. xxv ■ XMLPI ■ XMLROOT ■ XMLPARSE ■ XMLPI ■ XMLQUERY ■ XMLSERIALIZE ■ XMLTABLE The following datatypes are new in this release: ■ "SDO_TOPO_GEOMETRY" on page 2-35 The following pseudocolumns are new in this release: ■ COLUMN_VALUE Pseudocolumn on page 3-6 The following miscellaneous changes have been made: ■ Appendix C, "Oracle Regular Expression Support" on page C-1 lists the Perl-influenced operators that are now supported in Oracle regular expression functions and conditions. ■ Two new hints are provided to handle parallel join bitmap filtering: "PX_JOIN_ FILTER Hint" on page 2-93 and "NO_PX_JOIN_FILTER Hint" on page 2-88. ■ The new CHANGE NOTIFICATION system privilege is documented in GRANT on page 18-32. Oracle Database 10g Release 1 New Features in the SQL Reference The following datatypes are new in this release: ■ The binary floating-point datatypes BINARY_FLOAT on page 2-12 and BINARY_ DOUBLE on page 2-12 ■ The spatial datatype SDO_GEORASTER on page 2-35 ■ The interMedia datatype SI_StillImage on page 2-36 and six related Still Image object types The following top-level SQL statements are new or enhanced in this release: ■ A number of new top-level SQL statements have been added to support Automatic Storage Management: – CREATE DISKGROUP on page 14-44 – ALTER DISKGROUP on page 10-48 – DROP DISKGROUP on page 17-60 In addition, the following statements have added syntax in support of Automatic Storage Management: – file_specification subclauses, datafile_tempfile_spec and redo_log_ file_spec, let you specify Automatic Storage Management files in the form of ASM_filename on page 8-30, as well as file system files – CREATE CONTROLFILE on page 14-12 lets you specify Automatic Storage Management files as well as file system files
  • 26. xxvi – CREATE TABLESPACE on page 16-61 lets you create a tablespace within an Automatic Storage Management disk group using the "DATAFILE | TEMPFILE Clause" on page 16-65 ■ CREATE DATABASE on page 14-18 has new syntax that lets you create a default permanent tablespace for the database. ■ ALTER DATABASE on page 10-9 has new syntax that lets you: – Specify multiple temporary tablespaces (a tablespace group) as the database default temporary tablespaces – Assign or reassign a tablespace as the database default permanent tablespace (using the DEFAULT TABLESPACE clause) – Reset the target recovery incarnation for the database from the current incarnation to the prior incarnation – Begin backup of all the datafiles in the database – Enable block change tracking for incremental backups of the database – Update both global and local partitioned indexes as part of table partition maintenance operations – Revert the entire database, or some tablespaces of the database, to an earlier version – Control the relationship between primary databases and logical and physical standby databases – Assign or reassign a tablespace as the default permanent tablespace for the database – Add a logfile or enable a redo log thread by specifying an instance name rather than a thread number ■ ALTER MATERIALIZED VIEW LOG on page 11-15: – Has a new FORCE clause that lets you specify the addition of attributes that the materialized view log already has without causing Oracle to return an error – Lets you instruct Oracle Database to record a sequence value in the materialized view log ■ ALTER SYSTEM on page 11-60 has new syntax that lets you flush the buffer cache of the system global area (SGA). ■ ALTER TABLE on page 12-2 has new syntax that lets you manually compact the table segment, adjust the high water mark, and free the recuperated space. ■ ALTER TYPE on page 13-5 has new syntax that lets you modify varrays and nested tables of scalar types. ■ ALTER TABLESPACE on page 12-79 has new syntax that lets you: – Rename the tablespace – Guarantee that unexpired undo data will be preserved, even at the expense of ongoing transactions that require undo segment space ■ CREATE DATABASE on page 14-18 has new syntax that lets you: – Specify datafiles for the new SYSAUX system tablespace
  • 27. xxvii – Specify a bigfile tablespace as the default for the database and override the default for undo and default temporary tablespaces as well. A bigfile tablespace contains a single datafile that can be up to 4GB in size. – Create a default permanent tablespace for the database. ■ CREATE DIMENSION on page 14-36 and ALTER DIMENSION on page 10-45 have new syntax that lets you assign a name to a dimension attribute that is different from the level name. ■ CREATE INDEX on page 14-58 and ALTER INDEX on page 10-64 have new syntax that lets you create and maintain global hash-partitioned indexes. ■ CREATE INDEXTYPE on page 14-81 and ALTER INDEXTYPE on page 10-82 have new syntax that supports array inserts using the ODCIIndexInsert method. ■ CREATE MATERIALIZED VIEW on page 15-4 and ALTER MATERIALIZED VIEW on page 11-2 have new syntax that enhances refresh operations. ■ CREATE OPERATOR on page 15-32 and ALTER OPERATOR on page 11-21 have new syntax that lets you pass column information to the functional implementation of the operator. ■ CREATE TABLESPACE on page 16-61 has new syntax that lets you create a bigfile tablespace. Such a tablespace contains a single datafile that can contain up to 232 or 4G blocks, resulting in a datafile of up to 128 terabytes (TB). CREATE DATABASE on page 14-18 has related syntax that lets you specify a bigfile tablespace as the default, undo, and default temporary tablespace for the database. ■ CREATE TABLESPACE on page 16-61 and ALTER TABLESPACE on page 12-79 have new syntax that lets you assign or reassign a temporary tablespace to a tablespace group. ■ CREATE USER on page 17-26 and ALTER USER on page 13-18 have new syntax that lets you specify multiple temporary tablespaces (a tablespace group) to a user. ■ DROP TABLE on page 18-5 has a new PURGE clause that lets you drop the table without moving it to the recycle bin. ■ FLASHBACK DATABASE on page 18-23 is a new statement that lets you revert the entire database to an earlier version. ■ FLASHBACK TABLE on page 18-26 is a new statement that lets you revert one or more tables to an earlier system change number (SCN) or timestamp or retrieve a table that was dropped. ■ MERGE on page 18-71 has new syntax that lets you: – Specify either the update operation or the insert operation, or both – Delete rows from the target table during the update operation ■ PURGE on page 18-80 is a new SQL statement that lets you permanently remove previously dropped objects from the recycle bin and release the space that was associated with them. ■ SELECT on page 19-4 has new syntax that lets you: – Issue a versions query, which returns all incarnations of the rows returned by the query within a specified SCN or time range. – Perform a query on a partitioned outer join. The new syntax supports data densification, the process of querying sparse data along a particular
  • 28. xxviii dimension of data and returning rows that otherwise would have been omitted from the data returned by the query. – View the results of a query as a multidimensional array and perform associated calculations. The following clauses are modified in this release: ■ In the physical_attributes_clause on page 8-42, the MAXTRANS parameter has been deprecated. ■ The name of the data_segment_compression clause has been changed to table_compression for semantic clarity. The functionality has not changed. This clause appears in a number of SQL statements. For example, see CREATE TABLE table_compression on page 16-26. The following built-in functions are new in this release: ■ A new aggregate function COLLECT on page 5-35. ■ A new category of collection functions lets you manipulate nested tables and varrays. The collection functions are: – CARDINALITY on page 5-24 – POWERMULTISET on page 5-118 – POWERMULTISET_BY_CARDINALITY on page 5-119 – SET on page 5-155 ■ A new category of model functions are for use in specialized calculations and are valid only in the model_clause of a query. The model functions are: – CV on page 5-49 – PRESENTNNV on page 5-128 – PRESENTV on page 5-129 – PREVIOUS on page 5-130 ■ Functions to manipulate binary floating-point numbers: – TO_BINARY_DOUBLE on page 5-188 – TO_BINARY_FLOAT on page 5-189 – NANVL on page 5-98 – REMAINDER on page 5-147 ■ ORA_HASH on page 5-112 ■ The regular expression functions REGEXP_INSTR on page 5-136, REGEXP_ REPLACE on page 5-138, and REGEXP_SUBSTR on page 5-140. The Oracle Database implementation of regular expression support is discussed in Appendix C, "Oracle Regular Expression Support". ■ A new set of aggregate functions to support statistical analysis of data: – Correlation functions CORR_* on page 5-39 – MEDIAN on page 5-94 – STATS_BINOMIAL_TEST – STATS_CROSSTAB – STATS_F_TEST
  • 29. xxix – STATS_KS_TEST – STATS_MODE – STATS_MW_TEST – STATS_ONE_WAY_ANOVA – T-test functions STATS_T_TEST_* – STATS_WSR_TEST The following SQL operators a