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

SQL reference english ebook

1,5K 4,2K 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.498
Dung lượng 4,75 MB

Nội dung

IB M ® DB2 ® Universal Database SQL Reference Ve r s i o n 7 SC09-2974-00, SC09-2975-00  IB M ® DB2 ® Universal Database SQL Reference Ve r s i o n 7 SC09-2974-00, SC09-2975-00  Before using this information and the product it supports, be sure to read the general information under “Appendix S. Notices” on page 1447. This document contains proprietary information of IBM. It is provided under a license agreement and is protected by copyright law. The information contained in this publication does not include any product warranties, and any statements provided in this manual should not be interpreted as such. Order publications through your IBM representative or the IBM branch office serving your locality or by calling 1-800-879-2755 in the United States or 1-800-IBM-4YOU in Canada. When you send information to IBM, you grant IBM a nonexclusive right to use or distribute the information in any way it believes appropriate without incurring any obligation to you. © Copyright International Business Machines Corporation 1993, 2000. All rights reserved. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents Chapter 1. Introduction 1 Who Should Use This Book 1 How To Use This Book 1 How This Book is Structured 1 How to Read the Syntax Diagrams 3 Conventions Used in This Manual 5 Error Conditions 5 Highlighting Conventions 5 Related Documentation for This Book 6 Chapter 2. Concepts 9 Relational Database 9 Structured Query Language (SQL) 9 EmbeddedSQL 10 StaticSQL 10 Dynamic SQL 10 DB2 Call Level Interface (CLI) & Open Database Connectivity (ODBC) 10 Java Database Connectivity (JDBC) and Embedded SQL for Java (SQLJ) Programs . . 11 Interactive SQL 12 Schemas 12 Controlling Use of Schemas 12 Tables 13 Views 14 Aliases 15 Indexes 15 Keys 15 UniqueKeys 16 PrimaryKeys 16 ForeignKeys 16 Partitioning Keys 16 Constraints 16 Unique Constraints 17 Referential Constraints 17 Table Check Constraints 21 Triggers 21 EventMonitors 23 Queries 23 Table Expressions 23 Common Table Expressions 23 Packages 24 CatalogViews 24 Application Processes, Concurrency, and Recovery 24 IsolationLevel 27 RepeatableRead(RR) 28 Read Stability (RS) 28 Cursor Stability (CS) 29 Uncommitted Read (UR) 29 Comparison of Isolation Levels 29 Distributed Relational Database 29 Application Servers 30 CONNECT (Type 1) and CONNECT (Type 2) 31 RemoteUnitofWork 31 Application-Directed Distributed Unit of Work 35 Data Representation Considerations . . . 41 DB2 Federated Systems 41 The Federated Server, Federated Database, and Data Sources 41 Tasks to Perform in a DB2 Federated System 42 Wrappers and Wrapper Modules 43 Server Definitions and Server Options . . 44 User Mappings and User Options 46 Data Type Mappings 47 Function Mappings, Function Templates, and Function Mapping Options 48 Nicknames and Column Options 48 Index Specifications 49 Distributed Requests 50 Compensation 51 Pass-Through 51 Character Conversion 52 Character Sets and Code Pages 53 Code Page Attributes 54 Authorization and Privileges 55 Table Spaces and Other Storage Structures . . 58 Data Partitioning Across Multiple Partitions 59 Partitioning Maps 60 TableCollocation 61 Chapter 3. Language Elements 63 Characters 63 MBCSConsiderations 64 Tokens 64 MBCSConsiderations 65 Identifiers 65 © Copyright IBM Corp. 1993, 2000 iii SQL Identifiers 65 Host Identifiers 66 Naming Conventions and Implicit Object Name Qualifications 66 Aliases 71 Authorization IDs and authorization-names 72 Dynamic SQL Characteristics at run-time 73 Authorization IDs and Statement Preparation 75 DataTypes 75 Nulls 76 Large Objects (LOBs) 76 Character Strings 78 Graphic Strings 80 Binary String 81 Numbers 81 Datetime Values 82 DATALINKValues 85 User Defined Types 87 PromotionofDataTypes 90 Casting Between Data Types 91 AssignmentsandComparisons 94 Numeric Assignments 95 String Assignments 96 Datetime Assignments 99 DATALINKAssignments 99 User-defined Type Assignments 101 Reference Type Assignments 102 Numeric Comparisons 102 String Comparisons 102 Datetime Comparisons 106 User-defined Type Comparisons 106 Reference Type Comparisons 107 RulesforResultDataTypes 107 Character Strings 108 Graphic Strings 109 Binary Large Object (BLOB) 109 Numeric 109 DATE 110 TIME 110 TIMESTAMP 110 DATALINK 110 User-defined Types 110 Nullable Attribute of Result 111 Rules for String Conversions 111 Partition Compatibility 114 Constants 115 IntegerConstants 115 Floating-PointConstants 116 Decimal Constants 116 Character String Constants 116 Hexadecimal Constants 117 Graphic String Constants 117 Using Constants with User-defined Types 117 Special Registers 118 CURRENT DATE 118 CURRENT DEFAULT TRANSFORM GROUP 118 CURRENT DEGREE 119 CURRENT EXPLAIN MODE 120 CURRENT EXPLAIN SNAPSHOT . . . 121 CURRENT NODE 122 CURRENT PATH 122 CURRENT QUERY OPTIMIZATION . . 123 CURRENT REFRESH AGE 124 CURRENT SCHEMA 124 CURRENT SERVER 125 CURRENT TIME 125 CURRENT TIMESTAMP 125 CURRENT TIMEZONE 126 USER 126 ColumnNames 127 Qualified Column Names 127 CorrelationNames 127 Column Name Qualifiers to Avoid Ambiguity 130 Column Name Qualifiers in Correlated References 132 References to Host Variables 135 Host Variables in Dynamic SQL 135 References to BLOB, CLOB, and DBCLOB HostVariables 137 References to Locator Variables 138 References to BLOB, CLOB, and DBCLOB File Reference Variables 138 References to Structured Type Host Variables 141 Functions 142 External, SQL and Sourced User-Defined Functions 143 Scalar, Column, Row and Table User-Defined Functions 143 Function signatures 144 SQLPath 144 Function Resolution 144 Function Invocation 148 Methods 149 External and SQL User-Defined Methods 150 Method Signatures 150 Method Invocation 151 iv SQL Reference MethodResolution 151 Method of Choosing the Best Fit 153 Example of Method Resolution 154 Method Invocation 154 Conservative Binding Semantics 155 Expressions 157 Without Operators 158 With the Concatenation Operator . . . 158 With Arithmetic Operators 161 Two Integer Operands 162 Integer and Decimal Operands 162 Two Decimal Operands 162 Decimal Arithmetic in SQL 163 Floating-Point Operands 163 User-defined Types as Operands 163 Scalar Fullselect 164 Datetime Operations and Durations. . . 164 Datetime Arithmetic in SQL 165 Precedence of Operations 170 CASE Expressions 171 CAST Specifications 173 Dereference Operations 176 OLAP Functions 177 Method Invocation 183 Subtype Treatment 184 Predicates 186 BasicPredicate 187 Quantified Predicate 188 BETWEEN Predicate 191 EXISTSPredicate 193 INPredicate 194 LIKEPredicate 197 NULLPredicate 202 TYPE Predicate 203 Search Conditions 205 Examples 207 Chapter 4. Functions 209 ColumnFunctions 228 AVG 229 CORRELATION 231 COUNT 232 COUNT_BIG 234 COVARIANCE 236 GROUPING 237 MAX 239 MIN 241 REGRESSION Functions 243 STDDEV 247 SUM 248 VARIANCE 249 ScalarFunctions 250 ABS or ABSVAL 251 ACOS 252 ASCII 253 ASIN 254 ATAN 255 ATAN2 256 BIGINT 257 BLOB 258 CEILINGorCEIL 259 CHAR 260 CHR 265 CLOB 266 COALESCE 267 CONCAT 268 COS 269 COT 270 DATE 271 DAY 273 DAYNAME 274 DAYOFWEEK 275 DAYOFWEEK_ISO 276 DAYOFYEAR 277 DAYS 278 DBCLOB 279 DECIMAL 280 DEGREES 283 DEREF 284 DIFFERENCE 285 DIGITS 286 DLCOMMENT 287 DLLINKTYPE 288 DLURLCOMPLETE 289 DLURLPATH 290 DLURLPATHONLY 291 DLURLSCHEME 292 DLURLSERVER 293 DLVALUE 294 DOUBLE 296 EVENT_MON_STATE 298 EXP 299 FLOAT 300 FLOOR 301 GENERATE_UNIQUE 302 GRAPHIC 304 HEX 305 HOUR 307 INSERT 308 INTEGER 310 Contents v JULIAN_DAY 311 LCASE or LOWER 312 LCASE (SYSFUN schema) 313 LEFT 314 LENGTH 315 LN 317 LOCATE 318 LOG 319 LOG10 320 LONG_VARCHAR 321 LONG_VARGRAPHIC 322 LTRIM 323 LTRIM (SYSFUN schema) 324 MICROSECOND 325 MIDNIGHT_SECONDS 326 MINUTE 327 MOD 328 MONTH 329 MONTHNAME 330 NODENUMBER 331 NULLIF 333 PARTITION 334 POSSTR 336 POWER 338 QUARTER 339 RADIANS 340 RAISE_ERROR 341 RAND 343 REAL 344 REPEAT 345 REPLACE 346 RIGHT 347 ROUND 348 RTRIM 349 RTRIM (SYSFUN schema) 350 SECOND 351 SIGN 352 SIN 353 SMALLINT 354 SOUNDEX 355 SPACE 356 SQRT 357 SUBSTR 358 TABLE_NAME 362 TABLE_SCHEMA 364 TAN 366 TIME 367 TIMESTAMP 368 TIMESTAMP_ISO 370 TIMESTAMPDIFF 371 TRANSLATE 373 TRUNCATE or TRUNC 376 TYPE_ID 377 TYPE_NAME 378 TYPE_SCHEMA 379 UCASE or UPPER 380 VALUE 381 VARCHAR 382 VARGRAPHIC 384 WEEK 386 WEEK_ISO 387 YEAR 388 TableFunctions 389 SQLCACHE_SNAPSHOT 390 User-Defined Functions 391 Chapter 5. Queries 393 subselect 394 select-clause 395 from-clause 400 table-reference 401 joined-table 405 where-clause 408 group-by-clause 409 having-clause 416 Examples of subselects 418 Examples of Joins 421 Examples of Grouping Sets, Cube, and Rollup 425 fullselect 434 Examples of a fullselect 437 select-statement 439 common-table-expression 440 order-by-clause 443 update-clause 446 read-only-clause 447 fetch-first-clause 448 optimize-for-clause 449 Examples of a select-statement 450 Chapter 6. SQL Statements 453 How SQL Statements Are Invoked 457 Embedding a Statement in an Application Program 458 Dynamic Preparation and Execution . . 459 Static Invocation of a select-statement . . 459 Dynamic Invocation of a select-statement 460 Interactive Invocation 460 SQL Return Codes 461 SQLCODE 461 vi SQL Reference SQLSTATE 461 SQLComments 463 ALTER BUFFERPOOL 464 ALTERNICKNAME 466 ALTER NODEGROUP 469 ALTERSERVER 473 ALTER TABLE 477 ALTER TABLESPACE 503 ALTER TYPE (Structured) 509 ALTER USER MAPPING 516 ALTERVIEW 518 BEGIN DECLARE SECTION 520 CALL 522 CLOSE 530 COMMENTON 532 COMMIT 543 Compound SQL (Embedded) 545 CONNECT(Type1) 550 CONNECT(Type2) 558 CREATE ALIAS 566 CREATE BUFFERPOOL 569 CREATE DISTINCT TYPE 572 CREATE EVENT MONITOR 579 CREATE FUNCTION 589 CREATE FUNCTION (External Scalar) . . . 590 CREATE FUNCTION (External Table) . . . 615 CREATE FUNCTION (OLE DB External Table) 631 CREATE FUNCTION (Source or Template) 639 CREATE FUNCTION (SQL Scalar, Table or Row) 649 CREATE FUNCTION MAPPING 657 CREATE INDEX 662 CREATE INDEX EXTENSION 669 CREATE METHOD 676 CREATE NICKNAME 681 CREATE NODEGROUP 684 CREATE PROCEDURE 687 CREATE SCHEMA 704 CREATE SERVER 708 CREATE TABLE 712 CREATE TABLESPACE 764 CREATE TRANSFORM 774 CREATE TRIGGER 780 CREATE TYPE (Structured) 792 CREATE TYPE MAPPING 816 CREATE USER MAPPING 821 CREATE VIEW 823 CREATE WRAPPER 839 DECLARE CURSOR 841 DECLARE GLOBAL TEMPORARY TABLE 846 DELETE 855 DESCRIBE 860 DISCONNECT 865 DROP 868 END DECLARE SECTION 894 EXECUTE 895 EXECUTE IMMEDIATE 900 EXPLAIN 903 FETCH 908 FLUSH EVENT MONITOR 911 FREE LOCATOR 912 GRANT (Database Authorities) 913 GRANT (Index Privileges) 916 GRANT (Package Privileges) 918 GRANT (Schema Privileges) 921 GRANT (Server Privileges) 924 GRANT (Table, View, or Nickname Privileges) 926 GRANT (Table Space Privileges) 934 INCLUDE 936 INSERT 938 LOCK TABLE 947 OPEN 949 PREPARE 954 REFRESH TABLE 964 RELEASE (Connection) 965 RELEASE SAVEPOINT 967 RENAME TABLE 968 RENAME TABLESPACE 970 REVOKE (Database Authorities) 972 REVOKE (Index Privileges) 975 REVOKE (Package Privileges) 977 REVOKE (Schema Privileges) 980 REVOKE (Server Privileges) 982 REVOKE (Table, View, or Nickname Privileges) 984 REVOKE (Table Space Privileges) 990 ROLLBACK 992 SAVEPOINT 995 SELECT 997 SELECT INTO 998 SET CONNECTION 1000 SET CURRENT DEFAULT TRANSFORM GROUP 1002 SET CURRENT DEGREE 1004 SET CURRENT EXPLAIN MODE 1006 SET CURRENT EXPLAIN SNAPSHOT 1008 SET CURRENT PACKAGESET 1010 SET CURRENT QUERY OPTIMIZATION 1012 Contents vii SET CURRENT REFRESH AGE 1015 SET EVENT MONITOR STATE 1017 SET INTEGRITY 1019 SET PASSTHRU 1029 SETPATH 1031 SETSCHEMA 1033 SET SERVER OPTION 1035 SET transition-variable 1037 SIGNAL SQLSTATE 1041 UPDATE 1043 VALUES 1053 VALUES INTO 1054 WHENEVER 1056 Chapter 7. SQL Procedures 1059 SQLProcedureStatement 1060 ALLOCATE CURSOR Statement 1062 AssignmentStatement 1064 ASSOCIATE LOCATORS Statement . . . 1066 CASE Statement 1068 Compound Statement 1070 FORStatement 1076 GET DIAGNOSTICS Statement 1078 GOTOStatement 1080 IFStatement 1082 ITERATE Statement 1084 LEAVEStatement 1085 LOOP Statement 1086 REPEAT Statement 1088 RESIGNAL Statement 1090 RETURN Statement 1093 SIGNALStatement 1094 WHILEStatement 1097 Appendix A. SQL Limits 1099 Appendix B. SQL Communications (SQLCA) 1107 Viewing the SQLCA Interactively 1107 SQLCA Field Descriptions 1107 Order of Error Reporting 1111 DB2 Enterprise - Extended Edition Usage of the SQLCA 1112 Appendix C. SQL Descriptor Area (SQLDA) 1113 Field Descriptions 1113 Fields in the SQLDA Header 1115 Fields in an Occurrence of a Base SQLVAR 1116 Fields in an Occurrence of a Secondary SQLVAR 1118 Effect of DESCRIBE on the SQLDA . . . 1120 SQLTYPE and SQLLEN 1121 Unrecognized and Unsupported SQLTYPES 1123 Packed Decimal Numbers 1124 SQLLEN Field for Decimal 1125 Appendix D. Catalog Views 1127 Updatable Catalog Views 1128 ‘Roadmap’ toCatalogViews 1128 ‘Roadmap’ to Updatable Catalog Views 1130 SYSIBM.SYSDUMMY1 1131 SYSCAT.ATTRIBUTES 1132 SYSCAT.BUFFERPOOLNODES 1134 SYSCAT.BUFFERPOOLS 1135 SYSCAT.CASTFUNCTIONS 1136 SYSCAT.CHECKS 1137 SYSCAT.COLAUTH 1138 SYSCAT.COLCHECKS 1139 SYSCAT.COLDIST 1140 SYSCAT.COLOPTIONS 1141 SYSCAT.COLUMNS 1142 SYSCAT.CONSTDEP 1147 SYSCAT.DATATYPES 1148 SYSCAT.DBAUTH 1150 SYSCAT.EVENTMONITORS 1152 SYSCAT.EVENTS 1154 SYSCAT.FULLHIERARCHIES 1155 SYSCAT.FUNCDEP 1156 SYSCAT.FUNCMAPOPTIONS 1157 SYSCAT.FUNCMAPPARMOPTIONS . . . 1158 SYSCAT.FUNCMAPPINGS 1159 SYSCAT.FUNCPARMS 1160 SYSCAT.FUNCTIONS 1162 SYSCAT.HIERARCHIES 1167 SYSCAT.INDEXAUTH 1168 SYSCAT.INDEXCOLUSE 1169 SYSCAT.INDEXDEP 1170 SYSCAT.INDEXES 1171 SYSCAT.INDEXOPTIONS 1174 SYSCAT.KEYCOLUSE 1175 SYSCAT.NAMEMAPPINGS 1176 SYSCAT.NODEGROUPDEF 1177 SYSCAT.NODEGROUPS 1178 SYSCAT.PACKAGEAUTH 1179 SYSCAT.PACKAGEDEP 1180 SYSCAT.PACKAGES 1181 SYSCAT.PARTITIONMAPS 1185 viii SQL Reference [...]... ANSI standard definition of SQL v ISO/IEC 9075:1992, Database Language SQL – Contains the 1992 ISO standard definition of SQL v ISO/IEC 9075-2:1999, Database Language SQL Part 2: Foundation (SQL/ Foundation) – Contains a large portion of the 1999 ISO standard definition of SQL 6 SQL Reference v ISO/IEC 9075-4:1999, Database Language SQL Part 4: Persistent Stored Modules (SQL/ PSM) – Contains the 1999... of a query v The appendixes included in Volume 1 contain the following information: – “Appendix A SQL Limits” on page 1099 contains the SQL limitations – “Appendix B SQL Communications (SQLCA)” on page 1107 contains the SQLCA structure – “Appendix C SQL Descriptor Area (SQLDA)” on page 1113 contains the SQLDA structure – “Appendix D Catalog Views” on page 1127 contains the catalog views for the database... DB2 server Static SQL cannot be used by JDBC SQLJ applications use JDBC as a foundation for such tasks as connecting to databases and handling SQL errors, but can also contain embedded static SQL statements in the SQLJ source files An SQLJ source file has to be translated with the SQLJ translator before the resulting Java source code can be compiled For more information on JDBC and SQLJ applications,... preparation and binding All executable SQL statements must be prepared before they can be executed The result of preparation is the executable or operational form of the © Copyright IBM Corp 1993, 2000 9 statement The method of preparing an SQL statement and the persistence of its operational form distinguish static SQL from dynamic SQL Embedded SQL Embedded SQL statements are SQL statements written within... definition for SQL procedure control statements v ISO/IEC 9075-5:1999, Database Language SQL Part 4: Host Language Bindings (SQL/ Bindings) – Contains the 1999 ISO standard definition for host language bindings and dynamic SQL Chapter 1 Introduction 7 8 SQL Reference Chapter 2 Concepts The chapter provides an overview of the concepts commonly used in the Structured Query Language (SQL) The intent... specifications for DATALINKs Volume 2 contains the following sections: v “Chapter 6 SQL Statements” on page 453, contains syntax diagrams, semantic descriptions, rules, and examples of all SQL statements 2 SQL Reference v “Chapter 7 SQL Procedures” on page 1059, contains syntax diagrams, semantic descriptions, rules, and examples of SQL procedure statements How to Read the Syntax Diagrams Throughout this book,... static SQL statements must be processed by an SQL precompiler before it is compiled The precompiler turns the SQL statements into host language comments, and generates host language statements to invoke the database manager The syntax of the SQL statements is checked during the precompile process The preparation of an SQL application program includes precompilation, the binding of its static SQL statements... of the modified source program The steps are specified in the Application Development Guide Dynamic SQL Programs containing embedded dynamic SQL statements must be precompiled like those containing static SQL, but unlike static SQL, the dynamic SQL statements are constructed and prepared at run time The SQL statement text is prepared and executed using either the PREPARE and EXECUTE statements, or the... elements of SQL that span across IBM’s library of database products It provides limits and rules that assist in preparing portable programs using IBM databases It provides a list of SQL extensions and incompatibilities among the following standards and products: SQL9 2E, XPG4 -SQL, IBM -SQL and the IBM relational database products v American National Standard X3.135-1992, Database Language SQL – Contains... using CLI can return result sets to those programs The CLI Guide and Reference describes the APIs supported with this interface Java Database Connectivity (JDBC) and Embedded SQL for Java (SQLJ) Programs DB2 Universal Database implements two standards-based Java programming APIs: Java Database Connectivity (JDBC) and embedded SQL for Java (SQLJ) Both can be used to create Java applications and applets that . information: –“Appendix A. SQL Limits” on page 1099 contains the SQL limitations –“Appendix B. SQL Communications (SQLCA)” on page 1107 contains the SQLCA structure –“Appendix C. SQL Descriptor Area (SQLDA)” on. Correlated References 132 References to Host Variables 135 Host Variables in Dynamic SQL 135 References to BLOB, CLOB, and DBCLOB HostVariables 137 References to Locator Variables 138 References. Invocation of a select-statement 460 Interactive Invocation 460 SQL Return Codes 461 SQLCODE 461 vi SQL Reference SQLSTATE 461 SQLComments 463 ALTER BUFFERPOOL 464 ALTERNICKNAME 466 ALTER NODEGROUP

Ngày đăng: 22/10/2014, 16:48

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN