2569
DB2 10 for z/OS SQL Reference SC19-2983-06

01 a SQL Reference - DB2 10 for zOS - SC19-2983-06

Embed Size (px)

Citation preview

DB2 10 for z/OS

SQL Reference

SC19-2983-06

DB2 10 for z/OS

SQL Reference

SC19-2983-06

Note Before using this information and the product it supports, be sure to read the general information under Notices at the end of this information.

Seventh edition (June 2012) This edition applies to DB2 10 for z/OS (product number 5605-DB2), DB2 10 for z/OS Value Unit Edition (product number 5697-P31), and to any subsequent releases until otherwise indicated in new editions. Make sure you are using the correct edition for the level of the product. Specific changes are indicated by a vertical bar to the left of a change. A vertical bar to the left of a figure caption indicates that the figure has changed. Editorial changes that have no technical significance are not noted. Copyright IBM Corporation 1982, 2012. US Government Users Restricted Rights Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

ContentsAbout this information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . xixWho should read this information . . . . . . . . . . . . . . . . . . . . . . . . . . . xix DB2 Utilities Suite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix Terminology and citations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx Accessibility features for DB2 10 for z/OS . . . . . . . . . . . . . . . . . . . . . . . . . xx How to send your comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi How to read syntax diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii Conventions for describing mixed data values . . . . . . . . . . . . . . . . . . . . . . . xxiv Industry standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv

Chapter 1. DB2 concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Structured query language. . . . . . . . . . . . . Static SQL . . . . . . . . . . . . . . . . . Dynamic SQL . . . . . . . . . . . . . . . . Deferred embedded SQL . . . . . . . . . . . . Interactive SQL . . . . . . . . . . . . . . . SQL Call Level Interface and Open Database Connectivity . Java database connectivity and embedded SQL for Java . . DB2 data structures . . . . . . . . . . . . . . . DB2 tables . . . . . . . . . . . . . . . . . DB2 indexes . . . . . . . . . . . . . . . . DB2 keys . . . . . . . . . . . . . . . . . DB2 views . . . . . . . . . . . . . . . . . DB2 schemas and schema qualifiers . . . . . . . . DB2 storage groups. . . . . . . . . . . . . . DB2 databases . . . . . . . . . . . . . . . Storage structures . . . . . . . . . . . . . . . DB2 table spaces. . . . . . . . . . . . . . . DB2 index spaces . . . . . . . . . . . . . . DB2 hash spaces. . . . . . . . . . . . . . . . DB2 system objects . . . . . . . . . . . . . . . DB2 catalog . . . . . . . . . . . . . . . . DB2 directory. . . . . . . . . . . . . . . . Active and archive logs . . . . . . . . . . . . Bootstrap data set . . . . . . . . . . . . . . Buffer pools . . . . . . . . . . . . . . . . Data definition control support database . . . . . . Resource limit facility database . . . . . . . . . . Work file database . . . . . . . . . . . . . . DB2 and data integrity . . . . . . . . . . . . . Constraints . . . . . . . . . . . . . . . . Triggers . . . . . . . . . . . . . . . . . Application processes, concurrency, and recovery . . . . . Locking, commit, and rollback . . . . . . . . . . Unit of work . . . . . . . . . . . . . . . . Unit of recovery . . . . . . . . . . . . . . . Rolling back work . . . . . . . . . . . . . . Packages and application plans . . . . . . . . . . Routines . . . . . . . . . . . . . . . . . . Functions . . . . . . . . . . . . . . . . . Stored procedures . . . . . . . . . . . . . . Sequences . . . . . . . . . . . . . . . . . . User-defined types . . . . . . . . . . . . . . . Distributed data . . . . . . . . . . . . . . . . Connections . . . . . . . . . . . . . . . . Copyright IBM Corp. 1982, 2012

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . .

|

1 2 3 3 3 3 4 4 6 6 7 9 11 13 14 16 16 17 17 18 18 19 20 20 21 21 22 22 22 22 27 28 28 28 29 29 31 32 32 32 33 34 34 35

iii

Distributed unit of work . . . . . Remote unit of work . . . . . . Character conversion . . . . . . . Character sets and code pages . . . Coded character sets and CCSIDS . . Determining the encoding scheme and Expanding conversions . . . . . Contracting conversions . . . . .

. . . . . . . . . . . . . . . . . . . . CCSID of a . . . . . . . .

. . . . . . . . . . string . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

36 39 41 44 46 46 50 50

Chapter 2. Language elements . . . . . . . . . . . . . . . . . . . . . . . . . 51Characters . . . . . . . . . . . . . . . . . . . . . . . . Tokens . . . . . . . . . . . . . . . . . . . . . . . . . Identifiers . . . . . . . . . . . . . . . . . . . . . . . . SQL identifiers . . . . . . . . . . . . . . . . . . . . . Host identifiers . . . . . . . . . . . . . . . . . . . . . Restrictions for distributed access . . . . . . . . . . . . . . . Naming conventions . . . . . . . . . . . . . . . . . . . . SQL path . . . . . . . . . . . . . . . . . . . . . . . . Resolution of unqualified object names . . . . . . . . . . . . . . Qualification of unqualified object names . . . . . . . . . . . . . Unqualified alias, index, JAR file, sequence, table, trigger, and view names . Unqualified distinct type, function, procedure, and specific names . . . . Aliases and synonyms . . . . . . . . . . . . . . . . . . . . Authorization, privileges, permissions, masks, and object ownership . . . . Authorization IDs, roles, and authorization names . . . . . . . . . . Authorization IDs and schema names . . . . . . . . . . . . . Authorization IDs and statement preparation . . . . . . . . . . . Authorization IDs and dynamic SQL . . . . . . . . . . . . . . Authorization IDs and remote execution. . . . . . . . . . . . . Data types. . . . . . . . . . . . . . . . . . . . . . . . Nulls . . . . . . . . . . . . . . . . . . . . . . . . Numbers . . . . . . . . . . . . . . . . . . . . . . . Character strings . . . . . . . . . . . . . . . . . . . . Graphic strings . . . . . . . . . . . . . . . . . . . . . Binary strings . . . . . . . . . . . . . . . . . . . . . Large objects (LOBs) . . . . . . . . . . . . . . . . . . . Datetime values . . . . . . . . . . . . . . . . . . . . . Row ID values . . . . . . . . . . . . . . . . . . . . . XML values . . . . . . . . . . . . . . . . . . . . . . Distinct types . . . . . . . . . . . . . . . . . . . . . . Promotion of data types . . . . . . . . . . . . . . . . . . . Casting between data types . . . . . . . . . . . . . . . . . Implicit cast from numeric data to string data . . . . . . . . . . Implicit cast from string data to numeric data . . . . . . . . . . Assignment and comparison . . . . . . . . . . . . . . . . . Numeric assignments. . . . . . . . . . . . . . . . . . . String assignments . . . . . . . . . . . . . . . . . . . Datetime assignments . . . . . . . . . . . . . . . . . . Row ID assignments . . . . . . . . . . . . . . . . . . . XML assignments . . . . . . . . . . . . . . . . . . . . Distinct type assignments . . . . . . . . . . . . . . . . . Assignments to LOB locators . . . . . . . . . . . . . . . . Numeric comparisons . . . . . . . . . . . . . . . . . . String comparisons . . . . . . . . . . . . . . . . . . . Datetime comparisons . . . . . . . . . . . . . . . . . . Row ID comparisons . . . . . . . . . . . . . . . . . . . XML comparisons . . . . . . . . . . . . . . . . . . . . Distinct type comparisons . . . . . . . . . . . . . . . . . Rules for result data types . . . . . . . . . . . . . . . . . . Numeric operands. . . . . . . . . . . . . . . . . . . . Character and graphic string operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 . 52 . 53 . 53 . 54 . 55 . 55 . 61 . 62 . 63 . 63 . 63 . 64 . 66 . 68 . 70 . 70 . 71 . 73 . 76 . 77 . 77 . 80 . 90 . 91 . 92 . 94 . 101 . 102 . 103 . 104 . 105 . 113 . 113 . 115 . 119 . 123 . 126 . 127 . 127 . 127 . 129 . 129 . 130 . 131 . 132 . 133 . 133 . 134 . 135 . 136

|

|

| |

iv

SQL Reference

|

| |

Binary string operands . . . . . . . . . . . . . . . . . Datetime operands . . . . . . . . . . . . . . . . . . Row ID operands . . . . . . . . . . . . . . . . . . . XML operands . . . . . . . . . . . . . . . . . . . . Distinct type operands . . . . . . . . . . . . . . . . . Conversion rules for operations that combine strings . . . . . . . Constants . . . . . . . . . . . . . . . . . . . . . . Integer constants . . . . . . . . . . . . . . . . . . . Floating-point constants . . . . . . . . . . . . . . . . . Decimal constants . . . . . . . . . . . . . . . . . . . Decimal floating-point constants . . . . . . . . . . . . . . Character string constants . . . . . . . . . . . . . . . . Binary string constants . . . . . . . . . . . . . . . . . Datetime constants . . . . . . . . . . . . . . . . . . Graphic string constants . . . . . . . . . . . . . . . . . Special registers . . . . . . . . . . . . . . . . . . . . General rules for special registers. . . . . . . . . . . . . . CURRENT APPLICATION ENCODING SCHEME . . . . . . . . CURRENT CLIENT_ACCTNG . . . . . . . . . . . . . . CURRENT CLIENT_APPLNAME . . . . . . . . . . . . . CURRENT CLIENT_USERID . . . . . . . . . . . . . . . CURRENT CLIENT_WRKSTNNAME . . . . . . . . . . . . CURRENT DATE . . . . . . . . . . . . . . . . . . . CURRENT DEBUG MODE . . . . . . . . . . . . . . . . CURRENT DECFLOAT ROUNDING MODE . . . . . . . . . . CURRENT DEGREE . . . . . . . . . . . . . . . . . . CURRENT EXPLAIN MODE . . . . . . . . . . . . . . . CURRENT LOCALE LC_CTYPE . . . . . . . . . . . . . . CURRENT MAINTAINED TABLE TYPES FOR OPTIMIZATION . . . CURRENT MEMBER . . . . . . . . . . . . . . . . . . CURRENT OPTIMIZATION HINT . . . . . . . . . . . . . CURRENT PACKAGE PATH . . . . . . . . . . . . . . . CURRENT PACKAGESET . . . . . . . . . . . . . . . . CURRENT PATH . . . . . . . . . . . . . . . . . . . CURRENT PRECISION . . . . . . . . . . . . . . . . . CURRENT QUERY ACCELERATION . . . . . . . . . . . . CURRENT REFRESH AGE . . . . . . . . . . . . . . . . CURRENT ROUTINE VERSION . . . . . . . . . . . . . . CURRENT RULES. . . . . . . . . . . . . . . . . . . CURRENT SCHEMA . . . . . . . . . . . . . . . . . . CURRENT SERVER . . . . . . . . . . . . . . . . . . CURRENT SQLID . . . . . . . . . . . . . . . . . . . CURRENT TIME . . . . . . . . . . . . . . . . . . . CURRENT TIMESTAMP . . . . . . . . . . . . . . . . CURRENT TIME ZONE . . . . . . . . . . . . . . . . . ENCRYPTION PASSWORD . . . . . . . . . . . . . . . SESSION_USER . . . . . . . . . . . . . . . . . . . SESSION TIME ZONE . . . . . . . . . . . . . . . . . USER . . . . . . . . . . . . . . . . . . . . . . . Using special registers in a user-defined function or a stored procedure . Column names . . . . . . . . . . . . . . . . . . . . . Qualified column names. . . . . . . . . . . . . . . . . Correlation names . . . . . . . . . . . . . . . . . . . Column name qualifiers to avoid ambiguity . . . . . . . . . . Column name qualifiers in correlated references. . . . . . . . . Resolution of column name qualifiers and column names . . . . . References to variables . . . . . . . . . . . . . . . . . . References to host variables . . . . . . . . . . . . . . . Host variables in dynamic SQL . . . . . . . . . . . . . . References to LOB host variables . . . . . . . . . . . . . . References to LOB locator variables . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

137 137 138 138 138 138 142 143 143 143 143 144 145 145 149 150 151 153 154 155 156 157 158 158 159 160 161 162 163 163 164 164 165 165 166 167 168 169 169 170 171 171 172 173 174 174 174 175 175 176 178 179 179 180 182 183 185 185 188 188 189

Contents

v

|

References to XML host variables. . . . . . . . References to file reference variables. . . . . . . References to stored procedure result sets . . . . . References to result set locator variables . . . . . References to built-in session variables . . . . . . Host structures in PL/I, C, and COBOL . . . . . . Host-variable-arrays in PL/I, C, C++, and COBOL . . . Functions. . . . . . . . . . . . . . . . . Types of functions . . . . . . . . . . . . . Function invocation . . . . . . . . . . . . Function resolution . . . . . . . . . . . . Expressions . . . . . . . . . . . . . . . . Without operators . . . . . . . . . . . . . With arithmetic operators . . . . . . . . . . With the concatenation operator . . . . . . . . Scalar-fullselect . . . . . . . . . . . . . . Datetime operands and durations . . . . . . . Time zone specific expressions . . . . . . . . Datetime arithmetic in SQL. . . . . . . . . . Precedence of operations . . . . . . . . . . CASE expressions . . . . . . . . . . . . . CAST specification . . . . . . . . . . . . XMLCAST specification . . . . . . . . . . . OLAP specification . . . . . . . . . . . . ROW CHANGE expression. . . . . . . . . . Sequence reference . . . . . . . . . . . . Predicates . . . . . . . . . . . . . . . . Basic predicate . . . . . . . . . . . . . . Quantified predicate . . . . . . . . . . . . BETWEEN predicate . . . . . . . . . . . . DISTINCT predicate . . . . . . . . . . . . EXISTS predicate . . . . . . . . . . . . . IN predicate . . . . . . . . . . . . . . . LIKE predicate . . . . . . . . . . . . . . NULL predicate . . . . . . . . . . . . . XMLEXISTS predicate . . . . . . . . . . . Search conditions . . . . . . . . . . . . . . Options affecting SQL . . . . . . . . . . . . SQL processing options for dynamic statements . . . DECFLOAT rounding mode . . . . . . . . . Decimal point representation . . . . . . . . . Apostrophes and quotation marks as string delimiters. Katakana characters for EBCDIC . . . . . . . . Mixed data in character strings . . . . . . . . Formatting of datetime strings. . . . . . . . . SQL standard language . . . . . . . . . . . Positioned updates of columns . . . . . . . . Mappings from SQL to XML . . . . . . . . . . Mapping SQL character sets to XML character sets . . Mapping SQL identifiers to XML names . . . . . Mapping SQL data values to XML data values . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

190 191 192 193 194 197 198 199 199 201 201 208 210 210 217 220 221 222 224 228 230 234 243 245 252 254 259 261 263 266 267 269 271 274 280 281 284 285 287 288 288 290 291 291 292 292 293 294 294 294 294

Chapter 3. Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297Aggregate functions AVG . . . . CORRELATION COUNT . . . COUNT_BIG . COVARIANCE or MAX . . . . MIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . COVARIANCE_SAMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 307 308 309 310 312 313 314

vi

SQL Reference

|

| |

STDDEV or STDDEV_SAMP . . . . . . . . . SUM . . . . . . . . . . . . . . . . . VARIANCE or VARIANCE_SAMP . . . . . . . XMLAGG . . . . . . . . . . . . . . . Scalar functions . . . . . . . . . . . . . . ABS . . . . . . . . . . . . . . . . . ACOS . . . . . . . . . . . . . . . . . ADD_MONTHS . . . . . . . . . . . . . ASCII . . . . . . . . . . . . . . . . . ASCII_CHR . . . . . . . . . . . . . . . ASCII_STR . . . . . . . . . . . . . . . ASIN . . . . . . . . . . . . . . . . . ATAN . . . . . . . . . . . . . . . . . ATANH . . . . . . . . . . . . . . . . ATAN2 . . . . . . . . . . . . . . . . BIGINT . . . . . . . . . . . . . . . . BINARY . . . . . . . . . . . . . . . . BITAND, BITANDNOT, BITOR, BITXOR, and BITNOT BLOB . . . . . . . . . . . . . . . . . CCSID_ENCODING . . . . . . . . . . . . CEILING . . . . . . . . . . . . . . . . CHAR. . . . . . . . . . . . . . . . . CHARACTER_LENGTH . . . . . . . . . . CLOB . . . . . . . . . . . . . . . . . COALESCE . . . . . . . . . . . . . . . COLLATION_KEY . . . . . . . . . . . . COMPARE_DECFLOAT . . . . . . . . . . . CONCAT. . . . . . . . . . . . . . . . CONTAINS . . . . . . . . . . . . . . . COS . . . . . . . . . . . . . . . . . COSH . . . . . . . . . . . . . . . . . DATE . . . . . . . . . . . . . . . . . DAY . . . . . . . . . . . . . . . . . DAYOFMONTH . . . . . . . . . . . . . DAYOFWEEK . . . . . . . . . . . . . . DAYOFWEEK_ISO . . . . . . . . . . . . DAYOFYEAR . . . . . . . . . . . . . . DAYS . . . . . . . . . . . . . . . . . DBCLOB . . . . . . . . . . . . . . . . DECFLOAT . . . . . . . . . . . . . . . DECFLOAT_FORMAT . . . . . . . . . . . DECFLOAT_SORTKEY . . . . . . . . . . . DECIMAL or DEC . . . . . . . . . . . . DECODE . . . . . . . . . . . . . . . . DECRYPT_BINARY, DECRYPT_BIT, DECRYPT_CHAR, DEGREES . . . . . . . . . . . . . . . DIFFERENCE . . . . . . . . . . . . . . DIGITS . . . . . . . . . . . . . . . . DOUBLE_PRECISION or DOUBLE . . . . . . . DSN_XMLVALIDATE . . . . . . . . . . . EBCDIC_CHR . . . . . . . . . . . . . . EBCDIC_STR . . . . . . . . . . . . . . ENCRYPT_TDES . . . . . . . . . . . . . EXP . . . . . . . . . . . . . . . . . EXTRACT . . . . . . . . . . . . . . . FLOAT . . . . . . . . . . . . . . . . FLOOR . . . . . . . . . . . . . . . . GENERATE_UNIQUE . . . . . . . . . . . GETHINT . . . . . . . . . . . . . . . GETVARIABLE. . . . . . . . . . . . . . GRAPHIC . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . and DECRYPT_DB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

315 317 318 320 322 323 324 325 327 328 329 330 331 332 333 334 336 338 341 342 343 344 353 355 358 360 363 365 366 369 370 371 373 375 376 378 380 381 382 386 388 391 393 395 397 401 402 403 404 406 408 409 410 413 414 418 419 420 422 423 425

Contents

vii

| |

HEX . . . . . . . HOUR. . . . . . . IDENTITY_VAL_LOCAL IFNULL . . . . . . INSERT . . . . . . INTEGER or INT . . . JULIAN_DAY . . . . LAST_DAY . . . . . LCASE . . . . . . LEFT . . . . . . . LENGTH . . . . . . LN . . . . . . . . LOCATE . . . . . . LOCATE_IN_STRING . LOG10 . . . . . . LOWER . . . . . . LPAD . . . . . . . LTRIM . . . . . . MAX . . . . . . . MICROSECOND . . . MIDNIGHT_SECONDS . MIN . . . . . . . MINUTE . . . . . . MOD . . . . . . . MONTH . . . . . . MONTHS_BETWEEN . MQREAD . . . . . MQREADCLOB . . . MQRECEIVE . . . . MQRECEIVECLOB . . MQSEND . . . . . MULTIPLY_ALT . . . NEXT_DAY . . . . . NORMALIZE_DECFLOAT NORMALIZE_STRING . NULLIF . . . . . . NVL . . . . . . . OVERLAY . . . . . PACK . . . . . . . POSITION . . . . . POSSTR . . . . . . POWER . . . . . . QUANTIZE . . . . . QUARTER . . . . . RADIANS . . . . . RAISE_ERROR . . . . RAND. . . . . . . REAL . . . . . . . REPEAT . . . . . . REPLACE . . . . . RID . . . . . . . RIGHT . . . . . . ROUND . . . . . . ROUND_TIMESTAMP . ROWID . . . . . . RPAD . . . . . . . RTRIM . . . . . . SCORE . . . . . . SECOND . . . . . . SIGN . . . . . . . SIN. . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

429 430 432 437 438 442 444 446 448 449 453 455 456 459 462 463 466 468 470 471 473 475 476 478 480 482 484 486 488 490 492 494 495 497 498 500 501 502 506 509 512 514 515 517 519 520 521 522 524 526 529 530 532 534 537 538 540 542 545 547 548

viii

SQL Reference

| | |

| | |

|

|

|

SINH . . . . . . . . . . . . . . . SMALLINT . . . . . . . . . . . . . SOUNDEX . . . . . . . . . . . . . SOAPHTTPC and SOAPHTTPV . . . . . . SOAPHTTPNC and SOAPHTTPNV . . . . . SPACE . . . . . . . . . . . . . . SQRT . . . . . . . . . . . . . . . STRIP . . . . . . . . . . . . . . . SUBSTR . . . . . . . . . . . . . . SUBSTRING . . . . . . . . . . . . . TAN . . . . . . . . . . . . . . . TANH . . . . . . . . . . . . . . . TIME . . . . . . . . . . . . . . . TIMESTAMP . . . . . . . . . . . . TIMESTAMPADD . . . . . . . . . . . TIMESTAMP_FORMAT . . . . . . . . . TIMESTAMP_ISO . . . . . . . . . . . TIMESTAMPDIFF . . . . . . . . . . . TIMESTAMP_TZ . . . . . . . . . . . TO_CHAR . . . . . . . . . . . . . TO_DATE . . . . . . . . . . . . . TO_NUMBER . . . . . . . . . . . . TOTALORDER . . . . . . . . . . . . TRANSLATE . . . . . . . . . . . . TRIM . . . . . . . . . . . . . . . TRUNCATE or TRUNC . . . . . . . . . TRUNC_TIMESTAMP . . . . . . . . . UCASE . . . . . . . . . . . . . . UNICODE . . . . . . . . . . . . . UNICODE_STR . . . . . . . . . . . UPPER . . . . . . . . . . . . . . VALUE . . . . . . . . . . . . . . VARBINARY . . . . . . . . . . . . VARCHAR . . . . . . . . . . . . . VARCHAR_FORMAT . . . . . . . . . VARGRAPHIC . . . . . . . . . . . . VERIFY_GROUP_FOR_USER . . . . . . . VERIFY_ROLE_FOR_USER. . . . . . . . VERIFY_TRUSTED_CONTEXT_ROLE_FOR_USER WEEK . . . . . . . . . . . . . . . WEEK_ISO . . . . . . . . . . . . . XMLATTRIBUTES . . . . . . . . . . . XMLCOMMENT . . . . . . . . . . . XMLCONCAT . . . . . . . . . . . . XMLDOCUMENT . . . . . . . . . . . XMLELEMENT. . . . . . . . . . . . XMLFOREST . . . . . . . . . . . . XMLMODIFY . . . . . . . . . . . . XMLNAMESPACES . . . . . . . . . . XMLPARSE . . . . . . . . . . . . . XMLPI . . . . . . . . . . . . . . XMLQUERY. . . . . . . . . . . . . XMLSERIALIZE . . . . . . . . . . . XMLTEXT . . . . . . . . . . . . . XMLXSROBJECTID . . . . . . . . . . YEAR . . . . . . . . . . . . . . . Table functions . . . . . . . . . . . . . ADMIN_TASK_LIST . . . . . . . . . . ADMIN_TASK_OUTPUT . . . . . . . . ADMIN_TASK_STATUS . . . . . . . . . MQREADALL . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

549 550 552 553 555 557 558 559 560 563 569 570 571 572 575 577 583 584 587 589 590 591 592 594 598 600 602 605 606 607 609 611 612 614 620 630 634 636 638 640 641 643 644 645 646 647 652 655 658 660 662 663 667 670 671 672 673 674 679 681 685

Contents

ix

| |

MQREADALLCLOB . MQRECEIVEALL . . MQRECEIVEALLCLOB XMLTABLE . . . . Row functions . . . . UNPACK. . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

687 689 692 695 699 700

Chapter 4. Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 701Authorization . . . . . . . . . subselect . . . . . . . . . . . select-clause . . . . . . . . . from-clause . . . . . . . . . where-clause . . . . . . . . group-by-clause . . . . . . . having-clause . . . . . . . . order-by-clause . . . . . . . . fetch-first-clause . . . . . . . Examples of subselects . . . . . fullselect . . . . . . . . . . . Character conversion in set operations Selecting the result CCSID . . . . select-statement . . . . . . . . common-table-expression . . . . update-clause . . . . . . . . read-only-clause . . . . . . . optimize-clause. . . . . . . . isolation-clause . . . . . . . . queryno-clause . . . . . . . . SKIP LOCKED DATA . . . . . Examples of select statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . and concatenations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 702 704 705 713 728 730 732 733 736 738 744 748 749 751 752 755 757 758 759 761 762 763

Chapter 5. Statements

. . . . . . . . . . . . . . . . . . . . . . . . . . . . 765. . . . . . . in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . host language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 771 . 771 . 772 . 773 . 774 . 774 . 775 . 775 . 778 . 779 . 781 . 784 . 803 . 829 . 837 . 856 . 858 . 860 . 871 . 877 . 903 . 908 . 911 . 993 . 1012 . 1015 . 1027 . 1029

| | |

|

How SQL statements are invoked . . . . . . . . Embedding a statement in an application program . . Dynamic preparation and execution . . . . . . . Static invocation of a SELECT statement . . . . . Dynamic invocation of a SELECT statement . . . . Interactive invocation. . . . . . . . . . . . SQL diagnostics information . . . . . . . . . Detecting and processing error and warning conditions SQL comments . . . . . . . . . . . . . . . ALLOCATE CURSOR . . . . . . . . . . . . ALTER DATABASE . . . . . . . . . . . . . ALTER FUNCTION (external) . . . . . . . . . . ALTER FUNCTION (SQL scalar) . . . . . . . . . ALTER FUNCTION (SQL table) . . . . . . . . . ALTER INDEX . . . . . . . . . . . . . . . ALTER MASK . . . . . . . . . . . . . . . ALTER PERMISSION. . . . . . . . . . . . . ALTER PROCEDURE (external) . . . . . . . . . ALTER PROCEDURE (SQL - external) . . . . . . . ALTER PROCEDURE (SQL - native). . . . . . . . ALTER SEQUENCE . . . . . . . . . . . . . ALTER STOGROUP . . . . . . . . . . . . . ALTER TABLE . . . . . . . . . . . . . . . ALTER TABLESPACE . . . . . . . . . . . . ALTER TRIGGER . . . . . . . . . . . . . ALTER TRUSTED CONTEXT . . . . . . . . . ALTER VIEW . . . . . . . . . . . . . . . ASSOCIATE LOCATORS . . . . . . . . . . .

x

SQL Reference

| | |

BEGIN DECLARE SECTION . . . . . CALL . . . . . . . . . . . . CLOSE . . . . . . . . . . . . COMMENT . . . . . . . . . . COMMIT . . . . . . . . . . . CONNECT . . . . . . . . . . . CREATE ALIAS . . . . . . . . . CREATE AUXILIARY TABLE . . . . CREATE DATABASE . . . . . . . CREATE FUNCTION . . . . . . . CREATE FUNCTION (external scalar) . . CREATE FUNCTION (external table) . . CREATE FUNCTION (sourced) . . . . CREATE FUNCTION (SQL scalar) . . . CREATE FUNCTION (SQL table) . . . CREATE GLOBAL TEMPORARY TABLE . CREATE INDEX . . . . . . . . . CREATE MASK . . . . . . . . . CREATE PERMISSION . . . . . . . CREATE PROCEDURE . . . . . . . CREATE PROCEDURE (external) . . . CREATE PROCEDURE (SQL - external) . CREATE PROCEDURE (SQL - native) . . CREATE ROLE . . . . . . . . . CREATE SEQUENCE . . . . . . . CREATE STOGROUP . . . . . . . CREATE SYNONYM . . . . . . . CREATE TABLE . . . . . . . . . CREATE TABLESPACE. . . . . . . CREATE TRIGGER . . . . . . . . CREATE TRUSTED CONTEXT . . . . CREATE TYPE (distinct) . . . . . . CREATE VIEW . . . . . . . . . DECLARE CURSOR. . . . . . . . DECLARE GLOBAL TEMPORARY TABLE DECLARE STATEMENT . . . . . . DECLARE TABLE . . . . . . . . DECLARE VARIABLE . . . . . . . DELETE. . . . . . . . . . . . DESCRIBE . . . . . . . . . . . DESCRIBE CURSOR . . . . . . . DESCRIBE INPUT . . . . . . . . DESCRIBE OUTPUT . . . . . . . DESCRIBE PROCEDURE . . . . . . DESCRIBE TABLE . . . . . . . . DROP . . . . . . . . . . . . END DECLARE SECTION . . . . . EXCHANGE . . . . . . . . . . EXECUTE . . . . . . . . . . . EXECUTE IMMEDIATE . . . . . . EXPLAIN . . . . . . . . . . . FETCH . . . . . . . . . . . . FREE LOCATOR . . . . . . . . . GET DIAGNOSTICS . . . . . . . GRANT . . . . . . . . . . . . GRANT (collection privileges) . . . . GRANT (database privileges). . . . . GRANT (function or procedure privileges) GRANT (package privileges) . . . . . GRANT (plan privileges) . . . . . . GRANT (schema privileges) . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1033 1035 1047 1049 1059 1062 1069 1072 1076 1079 1080 1105 1124 1138 1163 1173 1179 1209 1219 1227 1228 1247 1259 1280 1281 1289 1292 1294 1359 1385 1402 1412 1420 1428 1440 1454 1455 1462 1465 1481 1482 1484 1487 1494 1497 1500 1519 1520 1521 1526 1529 1537 1563 1564 1581 1585 1586 1589 1594 1597 1598

Contents

xi

|

|

GRANT (sequence privileges) . . . . . . . . . . . . . GRANT (system privileges) . . . . . . . . . . . . . . GRANT (table or view privileges) . . . . . . . . . . . . GRANT (type or JAR file privileges) . . . . . . . . . . . GRANT (use privileges) . . . . . . . . . . . . . . . HOLD LOCATOR . . . . . . . . . . . . . . . . . INCLUDE . . . . . . . . . . . . . . . . . . . . INSERT . . . . . . . . . . . . . . . . . . . . . LABEL . . . . . . . . . . . . . . . . . . . . . LOCK TABLE . . . . . . . . . . . . . . . . . . . MERGE . . . . . . . . . . . . . . . . . . . . . OPEN . . . . . . . . . . . . . . . . . . . . . PREPARE . . . . . . . . . . . . . . . . . . . . REFRESH TABLE . . . . . . . . . . . . . . . . . RELEASE (connection) . . . . . . . . . . . . . . . . RELEASE SAVEPOINT . . . . . . . . . . . . . . . . RENAME . . . . . . . . . . . . . . . . . . . . REVOKE . . . . . . . . . . . . . . . . . . . . REVOKE (collection privileges) . . . . . . . . . . . . . REVOKE (database privileges) . . . . . . . . . . . . . REVOKE (function or procedure privileges) . . . . . . . . . REVOKE (package privileges) . . . . . . . . . . . . . REVOKE (plan privileges) . . . . . . . . . . . . . . . REVOKE (schema privileges) . . . . . . . . . . . . . . REVOKE (sequence privileges) . . . . . . . . . . . . . REVOKE (system privileges) . . . . . . . . . . . . . . REVOKE (table or view privileges) . . . . . . . . . . . . REVOKE (type or JAR file privileges) . . . . . . . . . . . REVOKE (use privileges) . . . . . . . . . . . . . . . ROLLBACK . . . . . . . . . . . . . . . . . . . SAVEPOINT . . . . . . . . . . . . . . . . . . . SELECT . . . . . . . . . . . . . . . . . . . . . SELECT INTO. . . . . . . . . . . . . . . . . . . SET CONNECTION . . . . . . . . . . . . . . . . . SET CURRENT APPLICATION ENCODING SCHEME . . . . . SET CURRENT DEBUG MODE . . . . . . . . . . . . . SET CURRENT DECFLOAT ROUNDING MODE . . . . . . . SET CURRENT DEGREE . . . . . . . . . . . . . . . SET CURRENT EXPLAIN MODE . . . . . . . . . . . . SET CURRENT LOCALE LC_CTYPE . . . . . . . . . . . SET CURRENT MAINTAINED TABLE TYPES FOR OPTIMIZATION SET CURRENT OPTIMIZATION HINT . . . . . . . . . . SET CURRENT PACKAGE PATH . . . . . . . . . . . . SET CURRENT PACKAGESET . . . . . . . . . . . . . SET CURRENT PRECISION . . . . . . . . . . . . . . SET CURRENT QUERY ACCELERATION . . . . . . . . . SET CURRENT REFRESH AGE . . . . . . . . . . . . . SET CURRENT ROUTINE VERSION . . . . . . . . . . . SET CURRENT RULES . . . . . . . . . . . . . . . . SET CURRENT SQLID . . . . . . . . . . . . . . . . SET ENCRYPTION PASSWORD . . . . . . . . . . . . SET host-variable assignment. . . . . . . . . . . . . . SET PATH . . . . . . . . . . . . . . . . . . . . SET SCHEMA . . . . . . . . . . . . . . . . . . . SET SESSION TIME ZONE . . . . . . . . . . . . . . SET transition-variable assignment . . . . . . . . . . . . SIGNAL. . . . . . . . . . . . . . . . . . . . . TRUNCATE . . . . . . . . . . . . . . . . . . . UPDATE . . . . . . . . . . . . . . . . . . . . VALUES. . . . . . . . . . . . . . . . . . . . . VALUES INTO . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1600 1601 1607 1611 1613 1615 1617 1619 1639 1641 1643 1657 1662 1684 1686 1688 1689 1693 1700 1702 1705 1712 1715 1717 1720 1722 1728 1732 1735 1738 1741 1743 1744 1748 1750 1751 1753 1756 1758 1760 1762 1764 1765 1769 1771 1772 1774 1776 1778 1779 1781 1783 1786 1789 1792 1793 1796 1797 1801 1821 1822

xii

SQL Reference

WHENEVER .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 1824

Chapter 6. SQL control statements for SQL routines . . . . . . . . . . . . . . . 1827References to SQL parameters and SQL variables . References to SQL condition names. . . . . . References to SQL cursor names. . . . . . . References to labels . . . . . . . . . . . Nested compound statements and scope of names SQL-procedure-statement . . . . . . . . . assignment-statement . . . . . . . . . . CALL statement . . . . . . . . . . . . CASE statement . . . . . . . . . . . . compound-statement . . . . . . . . . . FOR statement . . . . . . . . . . . . GET DIAGNOSTICS statement . . . . . . . GOTO statement . . . . . . . . . . . . IF statement . . . . . . . . . . . . . ITERATE statement . . . . . . . . . . . LEAVE statement. . . . . . . . . . . . LOOP statement . . . . . . . . . . . . REPEAT statement . . . . . . . . . . . RESIGNAL statement . . . . . . . . . . RETURN statement . . . . . . . . . . . SIGNAL statement . . . . . . . . . . . WHILE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1828 1829 1829 1829 1830 1832 1835 1837 1839 1841 1850 1852 1853 1855 1856 1858 1860 1862 1864 1867 1870 1874

Appendix. Additional information for DB2 SQL . . . . . . . . . . . . . . . . . 1875Limits in DB2 for z/OS . . . . . . . . . . . . . . . . Reserved schema names and reserved words . . . . . . . . . Reserved schema names . . . . . . . . . . . . . . . Reserved words . . . . . . . . . . . . . . . . . . Characteristics of SQL statements in DB2 for z/OS . . . . . . . Actions allowed on SQL statements . . . . . . . . . . . SQL statements allowed in external functions and stored procedures SQL control statements for external SQL procedures . . . . . . . References to SQL parameters and SQL variables . . . . . . . SQL-procedure-statement . . . . . . . . . . . . . . . assignment-statement (SQL control statements for external routines). CALL statement . . . . . . . . . . . . . . . . . . CASE statement . . . . . . . . . . . . . . . . . . compound-statement . . . . . . . . . . . . . . . . GET DIAGNOSTICS statement . . . . . . . . . . . . . GOTO statement . . . . . . . . . . . . . . . . . . IF statement . . . . . . . . . . . . . . . . . . . ITERATE statement . . . . . . . . . . . . . . . . . LEAVE statement. . . . . . . . . . . . . . . . . . LOOP statement . . . . . . . . . . . . . . . . . . REPEAT statement . . . . . . . . . . . . . . . . . RESIGNAL statement . . . . . . . . . . . . . . . . RETURN statement . . . . . . . . . . . . . . . . . SIGNAL statement . . . . . . . . . . . . . . . . . WHILE statement . . . . . . . . . . . . . . . . . SQL communication area (SQLCA) . . . . . . . . . . . . . Description of SQLCA fields . . . . . . . . . . . . . . The included SQLCA . . . . . . . . . . . . . . . . The REXX SQLCA . . . . . . . . . . . . . . . . . SQL descriptor area (SQLDA) . . . . . . . . . . . . . . Description of SQLDA fields . . . . . . . . . . . . . . Unrecognized and unsupported SQLTYPES . . . . . . . . . The included SQLDA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1876 1883 1884 1885 1889 1890 1894 1896 1897 1899 1900 1902 1904 1907 1913 1914 1916 1918 1919 1920 1922 1923 1926 1928 1932 1933 1934 1939 1941 1943 1945 1957 1958

Contents

xiii

| | | | | |

|

| | |

| |

Identifying an SQLDA in C or C++. . . The REXX SQLDA . . . . . . . . DB2 catalog tables . . . . . . . . . Table spaces and indexes . . . . . . New and changed catalog tables . . . SYSIBM.IPLIST table . . . . . . . SYSIBM.IPNAMES table . . . . . . SYSIBM.LOCATIONS table . . . . . SYSIBM.LULIST table . . . . . . . SYSIBM.LUMODES table . . . . . . SYSIBM.LUNAMES table . . . . . . SYSIBM.MODESELECT table . . . . . SYSIBM.SYSAUDITPOLICIES table. . . SYSIBM.SYSAUTOALERTS table . . . SYSIBM.SYSAUTOALERTS_OUT table . SYSIBM.SYSAUTORUNS_HIST table . . SYSIBM.SYSAUTORUNS_HISTOU table . SYSIBM.SYSAUTOTIMEWINDOWS table SYSIBM.SYSAUXRELS table . . . . . SYSIBM.SYSCHECKDEP table . . . . SYSIBM.SYSCHECKS table . . . . . SYSIBM.SYSCHECKS2 table . . . . . SYSIBM.SYSCOLAUTH table. . . . . SYSIBM.SYSCOLDIST table . . . . . SYSIBM.SYSCOLDISTSTATS table . . . SYSIBM.SYSCOLDIST_HIST table . . . SYSIBM.SYSCOLSTATS table . . . . . SYSIBM.SYSCOLUMNS table. . . . . SYSIBM.SYSCOLUMNS_HIST table . . SYSIBM.SYSCONSTDEP table . . . . SYSIBM.SYSCONTEXT table . . . . . SYSIBM.SYSCONTEXTAUTHIDS table . SYSIBM.SYSCONTROLS table . . . . SYSIBM.SYSCOPY table . . . . . . SYSIBM.SYSCTXTTRUSTATTRS table . . SYSIBM.SYSDATABASE table . . . . SYSIBM.SYSDATATYPES table . . . . SYSIBM.SYSDBAUTH table . . . . . SYSIBM.SYSDBRM table . . . . . . SYSIBM.SYSDEPENDENCIES table. . . SYSIBM.SYSDUMMY1 table . . . . . SYSIBM.SYSDUMMYA table . . . . . SYSIBM.SYSDUMMYE table . . . . . SYSIBM.SYSDUMMYU table . . . . . SYSIBM.SYSENVIRONMENT table. . . SYSIBM.SYSFIELDS table . . . . . . SYSIBM.SYSFOREIGNKEYS table . . . SYSIBM.SYSINDEXES table . . . . . SYSIBM.SYSINDEXES_HIST table . . . SYSIBM.SYSINDEXES_RTSECT table . . SYSIBM.SYSINDEXES_TREE table . . . SYSIBM.SYSINDEXPART table . . . . SYSIBM.SYSINDEXPART_HIST table . . SYSIBM.SYSINDEXSPACESTATS table . SYSIBM.SYSINDEXSTATS table . . . . SYSIBM.SYSINDEXSTATS_HIST table . . SYSIBM.SYSJARCLASS_SOURCE table . SYSIBM.SYSJARCONTENTS table . . . SYSIBM.SYSJARDATA table . . . . . SYSIBM.SYSJAROBJECTS table . . . . SYSIBM.SYSJAVAOPTS table . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1962 1963 1965 1967 1979 1983 1984 1987 1989 1990 1991 1994 1995 1999 2001 2002 2003 2004 2005 2006 2007 2008 2009 2011 2013 2015 2017 2019 2030 2034 2035 2037 2038 2040 2050 2051 2053 2055 2058 2060 2062 2063 2064 2065 2066 2068 2070 2071 2077 2079 2080 2081 2085 2087 2093 2095 2096 2097 2098 2099 2100

xiv

SQL Reference

|

| | | |

| | | |

|

| |

SYSIBM.SYSJAVAPATHS table . . . . SYSIBM.SYSKEYCOLUSE table . . . . SYSIBM.SYSKEYS table . . . . . . SYSIBM.SYSKEYTARGETS table. . . . SYSIBM.SYSKEYTARGETSTATS table . . SYSIBM.SYSKEYTARGETS_HIST table . SYSIBM.SYSKEYTGTDIST table . . . . SYSIBM.SYSKEYTGTDISTSTATS table . . SYSIBM.SYSKEYTGTDIST_HIST table . . SYSIBM.SYSLOBSTATS table . . . . . SYSIBM.SYSLOBSTATS_HIST table . . . SYSIBM.SYSOBJROLEDEP table . . . . SYSIBM.SYSPACKAGE table . . . . . SYSIBM.SYSPACKCOPY table . . . . SYSIBM.SYSPACKAUTH table . . . . SYSIBM.SYSPACKDEP table . . . . . SYSIBM.SYSPACKLIST table . . . . . SYSIBM.SYSPACKSTMT table . . . . SYSIBM.SYSPACKSTMT_STMB table . . SYSIBM.SYSPACKSTMT_STMT table . . SYSIBM.SYSPARMS table . . . . . . SYSIBM.SYSPENDINGDDL table . . . SYSIBM.SYSPENDINGOBJECTS table . . SYSIBM.SYSPKSYSTEM table . . . . SYSIBM.SYSPLAN table . . . . . . SYSIBM.SYSPLANAUTH table . . . . SYSIBM.SYSPLANDEP table . . . . . SYSIBM.SYSPLSYSTEM table. . . . . SYSIBM.SYSQUERY table . . . . . . SYSIBM.SYSQUERY_AUX table . . . . SYSIBM.SYSQUERYOPTS table . . . . SYSIBM.SYSQUERYPLAN table . . . . SYSIBM.SYSRELS table . . . . . . . SYSIBM.SYSRESAUTH table . . . . . SYSIBM.SYSROLES table . . . . . . SYSIBM.SYSROUTINEAUTH table . . . SYSIBM.SYSROUTINES table. . . . . SYSIBM.SYSROUTINESTEXT table . . . SYSIBM.SYSROUTINES_OPTS table . . SYSIBM.SYSROUTINES_TREE table . . SYSIBM.SYSROUTINES_SRC table . . . SYSIBM.SYSSCHEMAAUTH table . . . SYSIBM.SYSSEQUENCEAUTH table . . SYSIBM.SYSSEQUENCES table . . . . SYSIBM.SYSSEQUENCESDEP table . . SYSIBM.SYSSTMT table . . . . . . SYSIBM.SYSSTOGROUP table . . . . SYSIBM.SYSSTRINGS table . . . . . SYSIBM.SYSSYNONYMS table . . . . SYSIBM.SYSTABAUTH table . . . . . SYSIBM.SYSTABCONST table . . . . SYSIBM.SYSTABLEPART table . . . . SYSIBM.SYSTABLEPART_HIST table . . SYSIBM.SYSTABLES table . . . . . . SYSIBM.SYSTABLESPACE table . . . . SYSIBM.SYSTABLESPACESTATS table. . SYSIBM.SYSTABLES_HIST table. . . . SYSIBM.SYSTABLES_PROFILES table . . SYSIBM.SYSTABLES_PROFILE_TEXT table SYSIBM.SYSTABSTATS table . . . . . SYSIBM.SYSTABSTATS_HIST table . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2101 2102 2103 2104 2107 2109 2112 2114 2116 2118 2119 2120 2121 2130 2139 2141 2143 2144 2148 2149 2150 2154 2155 2156 2158 2163 2165 2166 2167 2169 2170 2171 2181 2183 2185 2186 2188 2199 2200 2202 2203 2204 2206 2208 2210 2211 2215 2217 2220 2221 2224 2225 2231 2234 2241 2247 2252 2254 2255 2256 2257

Contents

xv

|

| |

| | | | | | |

|

|

SYSIBM.SYSTRIGGERS table . . . . . . . . . . SYSIBM.SYSTRIGGERS_STMT table . . . . . . . SYSIBM.SYSUSERAUTH table . . . . . . . . . SYSIBM.SYSVIEWDEP table . . . . . . . . . . SYSIBM.SYSVIEWS table . . . . . . . . . . . SYSIBM.SYSVIEWS_STMT table . . . . . . . . . SYSIBM.SYSVIEWS_TREE table . . . . . . . . . SYSIBM.SYSVOLUMES table . . . . . . . . . . SYSIBM.SYSXMLRELS table . . . . . . . . . . SYSIBM.SYSXMLSTRINGS table. . . . . . . . . SYSIBM.USERNAMES table . . . . . . . . . . SYSIBM.SYSXMLTYPMOD table . . . . . . . . SYSIBM.SYSXMLTYPMSCHEMA table . . . . . . DB2 directory tables . . . . . . . . . . . . . . Directory table spaces and indexes . . . . . . . . SYSIBM.SYSLGRNX table . . . . . . . . . . . SYSIBM.SYSUTIL table . . . . . . . . . . . . SYSIBM.SYSUTILX table . . . . . . . . . . . Performance information for SQL application programming DB2 XML schema repository tables. . . . . . . . . XML schema repository (XSR) table spaces and indexes . SYSIBM.XSRCOMPONENT table . . . . . . . . SYSIBM.XSROBJECTS table . . . . . . . . . . SYSIBM.XSROBJECTCOMPONENTS table . . . . . SYSIBM.XSROBJECTGRAMMAR table . . . . . . SYSIBM.XSROBJECTHIERARCHIES table . . . . . SYSIBM.XSROBJECTPROPERTY table . . . . . . . SYSIBM.XSRPROPERTY table . . . . . . . . . EXPLAIN tables . . . . . . . . . . . . . . . PLAN_TABLE . . . . . . . . . . . . . . . DSN_COLDIST_TABLE . . . . . . . . . . . DSN_DETCOST_TABLE . . . . . . . . . . . DSN_FILTER_TABLE . . . . . . . . . . . . DSN_FUNCTION_TABLE . . . . . . . . . . . DSN_KEYTGTDIST_TABLE . . . . . . . . . . DSN_PGRANGE_TABLE . . . . . . . . . . . DSN_PGROUP_TABLE . . . . . . . . . . . . DSN_PREDICAT_TABLE . . . . . . . . . . . DSN_PTASK_TABLE . . . . . . . . . . . . DSN_QUERYINFO_TABLE . . . . . . . . . . DSN_QUERY_TABLE . . . . . . . . . . . . DSN_SORTKEY_TABLE . . . . . . . . . . . DSN_SORT_TABLE . . . . . . . . . . . . . DSN_STATEMENT_CACHE_TABLE . . . . . . . DSN_STATEMNT_TABLE . . . . . . . . . . . DSN_STRUCT_TABLE . . . . . . . . . . . . DSN_VIEWREF_TABLE . . . . . . . . . . . Tables that are used by accelerators . . . . . . . . Table spaces and indexes for accelerators . . . . . . SYSACCEL.SYSACCELERATORS table . . . . . . SYSACCEL.SYSACCELERATEDTABLES table . . . . Using the catalog in database design . . . . . . . . Retrieving catalog information about DB2 storage groups Retrieving catalog information about a table. . . . . Retrieving catalog information about partition order . . Retrieving catalog information about aliases. . . . . Retrieving catalog information about columns . . . . Retrieving catalog information about indexes . . . . Retrieving catalog information about views . . . . . Retrieving catalog information about authorizations . . Retrieving catalog information about primary keys . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2258 2260 2261 2265 2266 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2281 2281 2283 2284 2285 2286 2288 2289 2290 2291 2292 2293 2294 2310 2316 2324 2328 2332 2337 2340 2345 2351 2355 2360 2363 2367 2371 2376 2381 2385 2388 2389 2390 2391 2391 2392 2392 2393 2393 2394 2395 2395 2396 2396

xvi

SQL Reference

Retrieving catalog information about foreign keys . . . . Retrieving catalog information about check pending . . . Retrieving catalog information about check constraints . . Retrieving catalog information about LOBs . . . . . . Retrieving catalog information about user-defined functions Retrieving catalog information about triggers . . . . . Retrieving catalog information about sequences . . . . Adding and retrieving comments . . . . . . . . . Verifying the accuracy of the database definition . . . . Sample user-defined functions . . . . . . . . . . . ALTDATE . . . . . . . . . . . . . . . . . ALTTIME . . . . . . . . . . . . . . . . . CURRENCY . . . . . . . . . . . . . . . . DAYNAME. . . . . . . . . . . . . . . . . MONTHNAME . . . . . . . . . . . . . . . TABLE_LOCATION . . . . . . . . . . . . . . TABLE_NAME . . . . . . . . . . . . . . . TABLE_SCHEMA . . . . . . . . . . . . . . WEATHER . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . and stored procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . .

2397 2398 2399 2399 2400 2400 2401 2402 2402 2403 2404 2407 2409 2411 2412 2413 2415 2417 2419

Information resources for DB2 for z/OS and related products . . . . . . . . . . . 2421 How to obtain DB2 information . . . . . . . . . . . . . . . . . . . . . . . . 2427 How to use the DB2 library . . . . . . . . . . . . . . . . . . . . . . . . . . 2429 Notices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2433Programming Interface Information Trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2435 . 2435

Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2437 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2483

Contents

xvii

xviii

SQL Reference

About this informationThis book is a reference for Structured Query Language (SQL) for DB2 Universal Database for z/OS. Unless otherwise stated, references to SQL in this book imply SQL for DB2 UDB for z/OS, and all objects described in this book are objects of DB2 UDB for z/OS. This information assumes that your DB2 subsystem is running in Version 10 new-function mode. Generally, new functions that are described, including changes to existing functions, statements, and limits, are available only in new-function mode, unless explicitly stated otherwise. Exceptions to this general statement include optimization and virtual storage enhancements, which are also available in conversion mode unless stated otherwise. In Versions 8 and 9, most utility functions were available in conversion mode. However, for Version 10, most utility functions work only in new-function mode. The syntax and semantics of most SQL statements are essentially the same in all IBM relational database products, and the language elements common to the products provide a base for the definition of IBM SQL. Consult IBM DB2 Universal Database SQL Reference for Cross-Platform Development if you intend to develop applications that adhere to IBM SQL.

Who should read this informationThis information is intended for end users, application programmers, system and database administrators, and for persons involved in error detection and diagnosis. This information is a reference rather than a tutorial. It assumes that you are already familiar with SQL programming concepts. When you first use this information, consider reading Chapters 1 and 2 sequentially. These chapters describe the basic concepts of relational databases and SQL, the basic syntax of SQL, and the language elements that are common to many SQL statements. The rest of the chapters and appendixes are designed for the quick location of answers to specific SQL questions. They provide you with query forms, SQL statements, SQL procedure statements, DB2 limits, SQLCA, SQLDA, catalog tables, and SQL reserved words.

DB2 Utilities SuiteImportant: In this version of DB2 for z/OS, the DB2 Utilities Suite is available as an optional product. You must separately order and purchase a license to such utilities, and discussion of those utility functions in this publication is not intended to otherwise imply that you have a license to them. The DB2 Utilities Suite can work with DB2 Sort and the DFSORT program, which you are licensed to use in support of the DB2 utilities even if you do not otherwise license DFSORT for general use. If your primary sort product is not DFSORT, consider the following informational APARs mandatory reading: v II14047/II14213: USE OF DFSORT BY DB2 UTILITIES v II13495: HOW DFSORT TAKES ADVANTAGE OF 64-BIT REAL ARCHITECTURE Copyright IBM Corp. 1982, 2012

xix

These informational APARs are periodically updated. Related information DB2 utilities packaging (Utility Guide)

Terminology and citationsWhen referring to a DB2 product other than DB2 for z/OS, this information uses the product's full name to avoid ambiguity. The following terms are used as indicated: DB2 Represents either the DB2 licensed program or a particular DB2 subsystem. OMEGAMON Refers to any of the following products: v IBM Tivoli OMEGAMON XE for DB2 Performance Expert on z/OS v IBM Tivoli OMEGAMON XE for DB2 Performance Monitor on z/OS v IBM DB2 Performance Expert for Multiplatforms and Workgroups v IBM DB2 Buffer Pool Analyzer for z/OS C, C++, and C language Represent the C or C++ programming language. CICS Represents CICS Transaction Server for z/OS. IMS Represents the IMS Database Manager or IMS Transaction Manager. MVS Represents the MVS element of the z/OS operating system, which is equivalent to the Base Control Program (BCP) component of the z/OS operating system. RACF Represents the functions that are provided by the RACF component of the z/OS Security Server.

Accessibility features for DB2 10 for z/OSAccessibility features help a user who has a physical disability, such as restricted mobility or limited vision, to use information technology products successfully.

Accessibility featuresThe following list includes the major accessibility features in z/OS products, including DB2 10 for z/OS. These features support: v Keyboard-only operation. v Interfaces that are commonly used by screen readers and screen magnifiers. v Customization of display attributes such as color, contrast, and font size Tip: The Information Management Software for z/OS Solutions Information Center (which includes information for DB2 10 for z/OS) and its related publications are accessibility-enabled for the IBM Home Page Reader. You can operate all features using the keyboard instead of the mouse.

Keyboard navigationYou can access DB2 10 for z/OS ISPF panel functions by using a keyboard or keyboard shortcut keys.

xx

SQL Reference

For information about navigating the DB2 10 for z/OS ISPF panels using TSO/E or ISPF, refer to the z/OS TSO/E Primer, the z/OS TSO/E User's Guide, and the z/OS ISPF User's Guide. These guides describe how to navigate each interface, including the use of keyboard shortcuts or function keys (PF keys). Each guide includes the default settings for the PF keys and explains how to modify their functions.

Related accessibility informationOnline documentation for DB2 10 for z/OS is available in the Information Management Software for z/OS Solutions Information Center, which is available at the following website: http://publib.boulder.ibm.com/infocenter/imzic

IBM and accessibilitySee the IBM Accessibility Center at http://www.ibm.com/able for more information about the commitment that IBM has to accessibility.

How to send your commentsYour feedback helps IBM to provide quality information. Please send any comments that you have about this book or other DB2 for z/OS documentation. You can use the following methods to provide comments: v Send your comments by email to [email protected] and include the name of the product, the version number of the product, and the number of the book. If you are commenting on specific text, please list the location of the text (for example, a chapter and section title or a help topic title). v You can also send comments by using the Feedback link at the footer of each page in the Information Management Software for z/OS Solutions Information Center at http://publib.boulder.ibm.com/infocenter/imzic.

About this information

xxi

How to read syntax diagramsCertain conventions apply to the syntax diagrams that are used in IBM documentation. Apply the following rules when reading the syntax diagrams that are used in DB2 for z/OS documentation: v Read the syntax diagrams from left to right, from top to bottom, following the path of the line. The symbol indicates the beginning of a statement. The symbol indicates that the statement syntax is continued on the next line. The symbol indicates that a statement is continued from the previous line. The symbol indicates the end of a statement. v Required items appear on the horizontal line (the main path).required_item

v Optional items appear below the main path.required_item optional_item

If an optional item appears above the main path, that item has no effect on the execution of the statement and is used only for readability.optional_item required_item

v If you can choose from two or more items, they appear vertically, in a stack. If you must choose one of the items, one item of the stack appears on the main path.required_item required_choice1 required_choice2

If choosing one of the items is optional, the entire stack appears below the main path.required_item optional_choice1 optional_choice2

If one of the items is the default, it appears above the main path and the remaining choices are shown below.default_choice required_item optional_choice optional_choice

v An arrow returning to the left, above the main line, indicates an item that can be repeated.

xxii

SQL Reference

required_item

repeatable_item

If the repeat arrow contains a comma, you must separate repeated items with a comma., required_item repeatable_item

A repeat arrow above a stack indicates that you can repeat the items in the stack. v Sometimes a diagram must be split into fragments. The syntax fragment is shown separately from the main syntax diagram, but the contents of the fragment should be read as if they are on the main path of the diagram.required_item fragment-name

fragment-name:required_item optional_name

v With the exception of XPath keywords, keywords appear in uppercase (for example, FROM). Keywords must be spelled exactly as shown. XPath keywords are defined as lowercase names, and must be spelled exactly as shown. Variables appear in all lowercase letters (for example, column-name). They represent user-supplied names or values. v If punctuation marks, parentheses, arithmetic operators, or other such symbols are shown, you must enter them as part of the syntax.

About this information

xxiii

Conventions for describing mixed data valuesWhen mixed data values are shown in examples, certain conventions are used to represent these values. At sites using a double-byte character set (DBCS), character strings can include a mixture of single-byte and double-byte characters. When mixed data values are shown in the examples, the conventions shown in the following example apply:

Figure 1. Conventions used when mixed data values are shown in examples

xxiv

SQL Reference

Industry standardsDB2 for z/OS is developed based on specific industry standards for SQL. v ISO/IEC FCD 9075-1:2003, Information technology - Database languages - SQL - Part 1: Framework (SQL/Framework) v ISO/IEC FCD 9075-2:2003, Information technology - Database languages - SQL - Part 2: Foundation (SQL/Foundation) v ISO/IEC FCD 9075-3:2003, Information technology - Database languages - SQL - Part 3: Call-Level Interface (SQL/CLI) v ISO/IEC FCD 9075-4:2003, Information technology - Database languages - SQL - Part 4: Persistent Stored Modules (SQL/PSM) v ISO/IEC FCD 9075-5:2003, Information technology - Database languages - SQL- Part 5: Host Language Bindings (SQL/Bindings) v ISO/IEC FCD 9075-9:2003, Information technology - Database languages - SQL - Part 9: Management of External Data (SQL/MED) v ISO/IEC FCD 9075-10:2003, Information technology - Database languages - SQL - Part 10: Object Language Bindings (SQL/OLB) v ISO/IEC FCD 9075-11:2003, Information technology - Database languages - SQL - Part 11: Information and Definition Schemas (SQL/Schemata) v ISO/IEC FCD 9075-13:2003, Information technology - Database languages - SQL - Part 13: Java Routines and Types (SQL/JRT) v ISO/IEC FCD 9075-14:2006, Information technology - Database languages - SQL - Part 14: XML-Related Specifications (SQL/XML) v ANSI (American National Standards Institute) X3.135-1999, Database Language - SQL

About this information

xxv

xxvi

SQL Reference

Chapter 1. DB2 conceptsCertain DB2 concepts are important to understand when using Structured Query Language (SQL). The following topics provide information on these concepts: v Structured query language v DB2 schemas and schema qualifiers on page 11 v v v v v v DB2 tables on page 6 DB2 indexes on page 6 DB2 keys on page 7 Constraints on page 22 Triggers on page 27 Storage structures on page 16

v DB2 storage groups on page 13 v DB2 databases on page 14 v v v v v DB2 catalog on page 18 DB2 views on page 9 Sequences on page 33 Routines on page 32 Application processes, concurrency, and recovery on page 28

v Packages and application plans on page 31 v Distributed data on page 34 v Character conversion on page 41

Structured query languageThe language that you use to access the data in DB2 tables is the structured query language (SQL). SQL is a standardized language for defining and manipulating data in a relational database. The language consists of SQL statements. SQL statements let you accomplish the following actions: v Define, modify, or drop data objects, such as tables. v Retrieve, insert, update, or delete data in tables. Other SQL statements let you authorize users to access specific resources, such as tables or views. When you write an SQL statement, you s