1. Trang chủ
  2. » Công Nghệ Thông Tin

Oracle® Database SQL Language Reference ppt

1,6K 2,6K 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 1.630
Dung lượng 11,46 MB

Nội dung

Oracle® Database SQL Language Reference 11g Release 2 (11.2) E26088-03 December 2012 Oracle Database SQL Language Reference, 11g Release 2 (11.2) E26088-03 Copyright © 1996, 2012, Oracle and/or its affiliates. All rights reserved. Primary Authors: Diana Lorentz, Mary Beth Roeser Contributors: Sundeep Abraham, Angela Amor, Geeta Arora, Vikas Arora, Lance Ashdown, Hermann Baer, Shrikanth Bellamkonda, Donna Carver, Dan Chiba, Timothy Chien, Alan Choi, Thierry Cruanes, George Eadon, Amit Ganesh, Barb Glover, Naveen Gopal, Mike Hallas, Min-Hank Ho, Chandrasekharan Iyer, Mark Jaeger, Vikram Kapoor, Peter Knaggs, Srinath Krishnaswamy, Andre Kruglikov, Paul Lane, Huagang Li, Yunrui Li, Vince Liang, Bryn Llewellyn, Rich Long, Scott Lynn, Vineet Marwah, Jun Matsuzawa, Robert McGuirk, Rahil Mir, Gopal Mulagund, Sujatha Muthulingam, Hanlin Qian, Ashish Ray, John Russell, Laurent Schneider, Vivian Schupmann, Jia Shi, Ajeet Singh, Wayne Smith, Shanshan Song, Vinay Srihari, Jim Stenoish, Sankar Subramanian, Seema Sundara, Mark van de Wiel, Badhri Varanasi, William Waddington, Peter Wahl, Charles Wetherell, Sergiusz Wolicki, Daniel Wong, Tsae-feng Yu, Mohamed Zait, Fred Zemke, Wei Zhang, Weiran Zhang This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited. The information contained herein is subject to change without notice and is not warranted to be error-free. If you find any errors, please report them to us in writing. If this is software or related documentation that is delivered to the U.S. Government or anyone licensing it on behalf of the U.S. Government, the following notice is applicable: U.S. GOVERNMENT END USERS: Oracle programs, including any operating system, integrated software, any programs installed on the hardware, and/or documentation, delivered to U.S. Government end users are "commercial computer software" pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such, use, duplication, disclosure, modification, and adaptation of the programs, including any operating system, integrated software, any programs installed on the hardware, and/or documentation, shall be subject to license terms and license restrictions applicable to the programs. No other rights are granted to the U.S. Government. This software or hardware is developed for general use in a variety of information management applications. It is not developed or intended for use in any inherently dangerous applications, including applications that may create a risk of personal injury. If you use this software or hardware in dangerous applications, then you shall be responsible to take all appropriate fail-safe, backup, redundancy, and other measures to ensure its safe use. Oracle Corporation and its affiliates disclaim any liability for any damages caused by use of this software or hardware in dangerous applications. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. Intel and Intel Xeon are trademarks or registered trademarks of Intel Corporation. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. AMD, Opteron, the AMD logo, and the AMD Opteron logo are trademarks or registered trademarks of Advanced Micro Devices. UNIX is a registered trademark of The Open Group. This software or hardware and documentation may provide access to or information on content, products, and services from third parties. Oracle Corporation and its affiliates are not responsible for and expressly disclaim all warranties of any kind with respect to third-party content, products, and services. Oracle Corporation and its affiliates will not be responsible for any loss, costs, or damages incurred due to your access to or use of third-party content, products, or services. iii Contents Preface xxi Audience xxi Documentation Accessibility xxi Related Documents xxi Conventions xxii What's New in the SQL Language Reference? xxiii Oracle Database 11g Release 2 (11.2.0.2) New Features in the SQL Language Reference xxiii Oracle Database 11g Release 2 (11.2.0.1) New Features in the SQL Language Reference xxiii Oracle Database 11g Release 1 New Features in the SQL Language 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-2 Using Enterprise Manager 1-3 Lexical Conventions 1-3 Tools Support 1-3 2 Pseudocolumns Hierarchical Query Pseudocolumns 2-1 CONNECT_BY_ISCYCLE Pseudocolumn 2-1 CONNECT_BY_ISLEAF Pseudocolumn 2-2 LEVEL Pseudocolumn 2-2 Sequence Pseudocolumns 2-3 Where to Use Sequence Values 2-3 How to Use Sequence Values 2-4 Version Query Pseudocolumns 2-5 COLUMN_VALUE Pseudocolumn 2-6 OBJECT_ID Pseudocolumn 2-7 iv OBJECT_VALUE Pseudocolumn 2-8 ORA_ROWSCN Pseudocolumn 2-8 ROWID Pseudocolumn 2-9 ROWNUM Pseudocolumn 2-10 XMLDATA Pseudocolumn 2-11 3 Basic Elements of Oracle SQL Data Types 3-1 Oracle Built-in Data Types 3-6 CHAR Data Type 3-9 NCHAR Data Type 3-9 NVARCHAR2 Data Type 3-9 VARCHAR2 Data Type 3-10 VARCHAR Data Type 3-10 NUMBER Data Type 3-10 FLOAT Data Type 3-12 Floating-Point Numbers 3-13 BINARY_FLOAT 3-13 BINARY_DOUBLE 3-13 Numeric Precedence 3-14 DATE Data Type 3-17 Using Julian Days 3-17 TIMESTAMP Data Type 3-18 TIMESTAMP WITH TIME ZONE Data Type 3-18 TIMESTAMP WITH LOCAL TIME ZONE Data Type 3-19 INTERVAL YEAR TO MONTH Data Type 3-19 INTERVAL DAY TO SECOND Data Type 3-20 Datetime/Interval Arithmetic 3-20 Support for Daylight Saving Times 3-22 Datetime and Interval Examples 3-23 RAW and LONG RAW Data Types 3-24 BFILE Data Type 3-26 BLOB Data Type 3-26 CLOB Data Type 3-26 NCLOB Data Type 3-27 Rowid Data Types 3-27 ROWID Data Type 3-27 UROWID Data Type 3-28 ANSI, DB2, and SQL/DS Data Types 3-28 User-Defined Types 3-30 Object Types 3-30 REF Data Types 3-30 Varrays 3-31 Nested Tables 3-31 Oracle-Supplied Types 3-31 Any Types 3-32 ANYTYPE 3-32 v ANYDATA 3-32 ANYDATASET 3-32 XML Types 3-32 XMLType 3-32 URI Data Types 3-33 URIFactory Package 3-34 Spatial Types 3-34 SDO_GEOMETRY 3-34 SDO_TOPO_GEOMETRY 3-35 SDO_GEORASTER 3-35 Media Types 3-35 Expression Filter Type 3-36 Expression 3-37 Data Type Comparison Rules 3-37 Numeric Values 3-37 Date Values 3-37 Character Values 3-37 Object Values 3-40 Varrays and Nested Tables 3-40 Data Type Precedence 3-40 Data Conversion 3-40 Implicit and Explicit Data Conversion 3-40 Implicit Data Conversion 3-40 Implicit Data Conversion Examples 3-43 Explicit Data Conversion 3-43 Security Considerations for Data Conversion 3-44 Literals 3-45 Text Literals 3-46 Numeric Literals 3-47 Integer Literals 3-47 NUMBER and Floating-Point Literals 3-48 Datetime Literals 3-50 Interval Literals 3-53 INTERVAL YEAR TO MONTH 3-53 INTERVAL DAY TO SECOND 3-54 Format Models 3-56 Number Format Models 3-57 Number Format Elements 3-57 Datetime Format Models 3-60 Datetime Format Elements 3-60 Uppercase Letters in Date Format Elements 3-61 Punctuation and Character Literals in Datetime Format Models 3-61 Datetime Format Elements and Globalization Support 3-64 ISO Standard Date Format Elements 3-65 The RR Datetime Format Element 3-65 RR Datetime Format Examples 3-65 Datetime Format Element Suffixes 3-66 vi Format Model Modifiers 3-66 Format Model Examples 3-67 String-to-Date Conversion Rules 3-69 XML Format Model 3-70 Nulls 3-71 Nulls in SQL Functions 3-71 Nulls with Comparison Conditions 3-71 Nulls in Conditions 3-72 Comments 3-72 Comments Within SQL Statements 3-72 Comments on Schema and Nonschema Objects 3-73 Hints 3-74 Alphabetical Listing of Hints 3-79 ALL_ROWS Hint 3-79 APPEND Hint 3-80 APPEND_VALUES Hint 3-80 CACHE Hint 3-81 CHANGE_DUPKEY_ERROR_INDEX Hint 3-81 CLUSTER Hint 3-82 CURSOR_SHARING_EXACT Hint 3-82 DRIVING_SITE Hint 3-82 DYNAMIC_SAMPLING Hint 3-82 FACT Hint 3-83 FIRST_ROWS Hint 3-83 FULL Hint 3-84 HASH Hint 3-84 IGNORE_ROW_ON_DUPKEY_INDEX Hint 3-84 INDEX Hint 3-85 INDEX_ASC Hint 3-86 INDEX_COMBINE Hint 3-86 INDEX_DESC Hint 3-86 INDEX_FFS Hint 3-87 INDEX_JOIN Hint 3-87 INDEX_SS Hint 3-87 INDEX_SS_ASC Hint 3-88 INDEX_SS_DESC Hint 3-88 LEADING Hint 3-89 MERGE Hint 3-89 MODEL_MIN_ANALYSIS Hint 3-90 MONITOR Hint 3-90 NATIVE_FULL_OUTER_JOIN Hint 3-90 NOAPPEND Hint 3-90 NOCACHE Hint 3-90 NO_EXPAND Hint 3-91 NO_FACT Hint 3-91 NO_INDEX Hint 3-91 NO_INDEX_FFS Hint 3-92 vii NO_INDEX_SS Hint 3-92 NO_MERGE Hint 3-92 NO_MONITOR Hint 3-93 NO_NATIVE_FULL_OUTER_JOIN Hint 3-93 NO_PARALLEL Hint 3-93 NOPARALLEL Hint 3-93 NO_PARALLEL_INDEX Hint 3-93 NOPARALLEL_INDEX Hint 3-94 NO_PUSH_PRED Hint 3-94 NO_PUSH_SUBQ Hint 3-94 NO_PX_JOIN_FILTER Hint 3-94 NO_QUERY_TRANSFORMATION Hint 3-94 NO_RESULT_CACHE Hint 3-95 NO_REWRITE Hint 3-95 NOREWRITE Hint 3-95 NO_STAR_TRANSFORMATION Hint 3-95 NO_STATEMENT_QUEUING Hint 3-95 NO_UNNEST Hint 3-96 NO_USE_HASH Hint 3-96 NO_USE_MERGE Hint 3-96 NO_USE_NL Hint 3-96 NO_XML_QUERY_REWRITE Hint 3-97 NO_XMLINDEX_REWRITE Hint 3-97 OPT_PARAM Hint 3-97 ORDERED Hint 3-97 PARALLEL Hint 3-98 PARALLEL_INDEX Hint 3-100 PQ_DISTRIBUTE Hint 3-100 PUSH_PRED Hint 3-103 PUSH_SUBQ Hint 3-103 PX_JOIN_FILTER Hint 3-103 QB_NAME Hint 3-103 RESULT_CACHE Hint 3-104 RETRY_ON_ROW_CHANGE Hint 3-104 REWRITE Hint 3-104 STAR_TRANSFORMATION Hint 3-105 STATEMENT_QUEUING Hint 3-105 UNNEST Hint 3-106 USE_CONCAT Hint 3-106 USE_HASH Hint 3-106 USE_MERGE Hint 3-107 USE_NL Hint 3-107 USE_NL_WITH_INDEX Hint 3-108 Database Objects 3-108 Schema Objects 3-108 Nonschema Objects 3-109 Database Object Names and Qualifiers 3-109 viii Database Object Naming Rules 3-109 Schema Object Naming Examples 3-113 Schema Object Naming Guidelines 3-113 Syntax for Schema Objects and Parts in SQL Statements 3-113 How Oracle Database Resolves Schema Object References 3-114 References to Objects in Other Schemas 3-115 References to Objects in Remote Databases 3-115 Creating Database Links 3-116 Database Link Names 3-116 Username and Password 3-117 Database Connect String 3-117 References to Database Links 3-117 References to Partitioned Tables and Indexes 3-118 References to Object Type Attributes and Methods 3-119 4 Operators About SQL Operators 4-1 Unary and Binary Operators 4-2 Operator Precedence 4-2 Arithmetic Operators 4-3 Concatenation Operator 4-4 Hierarchical Query Operators 4-5 PRIOR 4-5 CONNECT_BY_ROOT 4-5 Set Operators 4-5 Multiset Operators 4-6 MULTISET EXCEPT 4-6 MULTISET INTERSECT 4-7 MULTISET UNION 4-8 User-Defined Operators 4-9 5 Functions About SQL Functions 5-2 Single-Row Functions 5-3 Numeric Functions 5-3 Character Functions Returning Character Values 5-4 Character Functions Returning Number Values 5-5 NLS Character Functions 5-5 Datetime Functions 5-5 General Comparison Functions 5-6 Conversion Functions 5-6 Large Object Functions 5-7 Collection Functions 5-7 Hierarchical Functions 5-7 Data Mining Functions 5-7 XML Functions 5-8 Encoding and Decoding Functions 5-9 ix NULL-Related Functions 5-9 Environment and Identifier Functions 5-9 Aggregate Functions 5-10 Analytic Functions 5-11 Object Reference Functions 5-17 Model Functions 5-17 OLAP Functions 5-17 Data Cartridge Functions 5-17 Alphabetical Listing of SQL Functions 5-17 ABS 5-18 ACOS 5-19 ADD_MONTHS 5-20 APPENDCHILDXML 5-21 ASCII 5-22 ASCIISTR 5-23 ASIN 5-24 ATAN 5-25 ATAN2 5-26 AV G 5-27 BFILENAME 5-29 BIN_TO_NUM 5-30 BITAND 5-32 CARDINALITY 5-34 CAST 5-35 CEIL 5-38 CHARTOROWID 5-39 CHR 5-40 CLUSTER_ID 5-42 CLUSTER_PROBABILITY 5-44 CLUSTER_SET 5-46 COALESCE 5-48 COLLECT 5-50 COMPOSE 5-51 CONCAT 5-52 CONVERT 5-53 CORR 5-55 CORR_* 5-57 CORR_S 5-58 CORR_K 5-59 COS 5-60 COSH 5-61 COUNT 5-62 COVAR_POP 5-64 COVAR_SAMP 5-66 CUBE_TABLE 5-67 CUME_DIST 5-69 CURRENT_DATE 5-71 x CURRENT_TIMESTAMP 5-72 CV 5-73 DATAOBJ_TO_PARTITION 5-75 DBTIMEZONE 5-76 DECODE 5-77 DECOMPOSE 5-79 DELETEXML 5-80 DENSE_RANK 5-82 DEPTH 5-84 DEREF 5-85 DUMP 5-86 EMPTY_BLOB, EMPTY_CLOB 5-88 EXISTSNODE 5-89 EXP 5-90 EXTRACT (datetime) 5-91 EXTRACT (XML) 5-94 EXTRACTVALUE 5-95 FEATURE_ID 5-96 FEATURE_SET 5-97 FEATURE_VALUE 5-99 FIRST 5-101 FIRST_VALUE 5-103 FLOOR 5-105 FROM_TZ 5-106 GREATEST 5-107 GROUP_ID 5-108 GROUPING 5-109 GROUPING_ID 5-110 HEXTORAW 5-111 INITCAP 5-112 INSERTCHILDXML 5-113 INSERTCHILDXMLAFTER 5-115 INSERTCHILDXMLBEFORE 5-116 INSERTXMLAFTER 5-117 INSERTXMLBEFORE 5-118 INSTR 5-119 ITERATION_NUMBER 5-121 LAG 5-123 LAST 5-125 LAST_DAY 5-126 LAST_VALUE 5-127 LEAD 5-130 LEAST 5-132 LENGTH 5-133 LISTAGG 5-134 LN 5-136 LNNVL 5-137 [...]... "Database Language SQL" , Parts 1 ( "SQL/ Framework"), 2 ( "SQL/ Foundation"), 3 ( "SQL/ CLI"), 4 ( "SQL/ PSM"), 9 Introduction to Oracle SQL 1-1 SQL Standards ( "SQL/ MED"), 10 ( "SQL/ OLB"), 11( "SQL/ Schemata"), 13 ( "SQL/ JRT"), and ANSI/ISO/IEC 9075-14:2008, "Database Language SQL" , Part 14 ( "SQL/ XML") ■ ISO/IEC 9075:2008, "Database Language SQL" , Parts 1 ( "SQL/ Framework"), 2 ( "SQL/ Foundation"), 3 ( "SQL/ CLI"), 4 ( "SQL/ PSM"),... partition or subpartition Oracle Database 11g Release 2 (11.2.0.1) New Features in the SQL Language Reference Structural Changes in the SQL Language Reference A number of sections of this book that were made up primarily of PL /SQL were moved to Oracle Database PL /SQL Language Reference in Oracle Database 11g Release 1 Please refer to "Structural Changes in the SQL Language Reference" on page xxvi for details... cycles in the recursion Oracle Database 11g Release 1 New Features in the SQL Language xxv Reference Structural Changes in the SQL Language Reference A number of SQL statements are constructed almost entirely of PL /SQL elements Those statements continue to appear in this reference, but the bulk of their syntax and semantics has been moved to Oracle Database PL /SQL Language Reference The following table... ( "SQL/ PSM"), 9 ( "SQL/ MED"), 10 ( "SQL/ OLB"), 11( "SQL/ Schemata"), 13 ( "SQL/ JRT"), and ISO/IEC 9075-14:2008, "Database Language SQL" , Part 14 ( "SQL/ XML") See Also: Appendix C, "Oracle and Standard SQL" for a detailed description of Oracle Database conformance to the SQL: 2008 standards How SQL Works The strengths of SQL provide benefits for all types of users, including application programmers, database administrators,... New in the SQL Language Reference? This section describes new features of Oracle Database 11g and provides pointers to additional information For information on features that were new in earlier versions of Oracle Database, refer to the documentation for the earlier release Oracle Database 11g Release 2 (11.2.0.2) New Features in the SQL Language Reference New Features in the SQL Language Reference. .. Controlling access to the database and its objects ■ Guaranteeing database consistency and integrity SQL unifies all of the preceding tasks in one consistent language Common Language for All Relational Databases All major relational database management systems support SQL, so you can transfer all skills you have gained with SQL from one database to another In addition, all programs written in SQL are portable... administrators, managers, and end users Technically speaking, SQL is a data sublanguage The purpose of SQL is to provide an interface to a relational database such as Oracle Database, and all SQL statements are instructions to the database In this SQL differs from general-purpose programming languages like C and BASIC Among the features of SQL are the following: ■ It processes sets of data as groups... E Oracle SQL Reserved Words and Keywords Oracle SQL Reserved Words E-1 Oracle SQL Keywords E-3 F Extended Examples Using Extensible Indexing F-1 Using XML in SQL Statements F-8 Index xx 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... to Oracle SQL Structured Query Language (SQL) is the set of statements with which all programs and users access data in an Oracle Database Application programs and Oracle tools often allow users access to the database without using SQL directly, but these applications in turn must use SQL when executing the user's request This chapter provides background information on SQL as used by most database systems... Documents For more information, see these Oracle resources: ■ ■ Oracle Database PL /SQL Language 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 xxi Many of the examples in this book use the sample schemas, which . the SQL Language Reference? xxiii Oracle Database 11g Release 2 (11.2.0.2) New Features in the SQL Language Reference xxiii Oracle Database 11g Release 2 (11.2.0.1) New Features in the SQL Language. Language Reference xxiii Oracle Database 11g Release 1 New Features in the SQL Language Reference xxv 1 Introduction to Oracle SQL History of SQL 1-1 SQL Standards 1-1 How SQL Works 1-2 Common Language. Oracle® Database SQL Language Reference 11g Release 2 (11.2) E26088-03 December 2012 Oracle Database SQL Language Reference, 11g Release 2 (11.2) E26088-03 Copyright

Ngày đăng: 30/03/2014, 22:20

TỪ KHÓA LIÊN QUAN