db2 for sql

2591
DB2 10 for z/OS SQL Reference SC19-2983-11

Upload: ramesh-dwarapudi

Post on 27-Dec-2015

107 views

Category:

Documents


18 download

TRANSCRIPT

  • DB2 10 for z/OS

    SQL Reference

    SC19-2983-11

  • DB2 10 for z/OS

    SQL Reference

    SC19-2983-11

  • NoteBefore using this information and the product it supports, be sure to read the general information under Notices at theend of this information.

    Twelfth edition (February 2014)

    This edition applies to DB2 10 for z/OS (product number 5605-DB2), DB2 10 for z/OS Value Unit Edition (productnumber 5697-P31), and to any subsequent releases until otherwise indicated in new editions. Make sure you areusing 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 captionindicates that the figure has changed. Editorial changes that have no technical significance are not noted.

    Copyright IBM Corporation 1982, 2014.US Government Users Restricted Rights Use, duplication or disclosure restricted by GSA ADP Schedule Contractwith IBM Corp.

  • ContentsAbout this information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . xixWho should read this information . . . . . . . . . . . . . . . . . . . . . . . . . . . xixDB2 Utilities Suite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xixTerminology and citations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxAccessibility features for DB2 10 for z/OS . . . . . . . . . . . . . . . . . . . . . . . . . xxHow to send your comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiHow to read syntax diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiiConventions for describing mixed data values . . . . . . . . . . . . . . . . . . . . . . . xxivIndustry standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv

    Chapter 1. DB2 concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Structured query language. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

    Static SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Dynamic SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Deferred embedded SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Interactive SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3SQL Call Level Interface and Open Database Connectivity . . . . . . . . . . . . . . . . . . . 3Java database connectivity and embedded SQL for Java . . . . . . . . . . . . . . . . . . . . 4

    DB2 data structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4DB2 tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6DB2 indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6DB2 keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7DB2 views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9DB2 schemas and schema qualifiers . . . . . . . . . . . . . . . . . . . . . . . . . . 11DB2 storage groups. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13DB2 databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

    Storage structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16DB2 table spaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16DB2 index spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

    DB2 hash spaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17DB2 system objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

    DB2 catalog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18DB2 directory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19Active and archive logs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20Bootstrap data set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21Buffer pools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21Data definition control support database . . . . . . . . . . . . . . . . . . . . . . . . 22Resource limit facility tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Work file database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

    DB2 and data integrity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

    Application processes, concurrency, and recovery. . . . . . . . . . . . . . . . . . . . . . . 28Locking, commit, and rollback . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28Unit of work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Unit of recovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30Rolling back work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30Packages and application plans . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

    Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32Stored procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

    Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34User-defined types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35Distributed data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

    Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

    Copyright IBM Corp. 1982, 2014 iii

    ||

  • Distributed unit of work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37Remote unit of work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

    Character conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42Character sets and code pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45Coded character sets and CCSIDS . . . . . . . . . . . . . . . . . . . . . . . . . . . 47Determining the encoding scheme and CCSID of a string . . . . . . . . . . . . . . . . . . . 47Expanding conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51Contracting conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

    Chapter 2. Language elements . . . . . . . . . . . . . . . . . . . . . . . . . 53Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53Tokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

    SQL identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55Host identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56Restrictions for distributed access . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

    Naming conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57SQL path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63Resolution of unqualified object names . . . . . . . . . . . . . . . . . . . . . . . . . . 64Qualification of unqualified object names . . . . . . . . . . . . . . . . . . . . . . . . . 65

    Unqualified alias, index, JAR file, sequence, table, trigger, and view names . . . . . . . . . . . . . 65Unqualified distinct type, function, procedure, and specific names . . . . . . . . . . . . . . . . 65

    Aliases and synonyms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66Authorization, privileges, permissions, masks, and object ownership . . . . . . . . . . . . . . . . 68Authorization IDs, roles, and authorization names . . . . . . . . . . . . . . . . . . . . . . 70

    Authorization IDs and schema names . . . . . . . . . . . . . . . . . . . . . . . . . 72Authorization IDs and statement preparation . . . . . . . . . . . . . . . . . . . . . . . 72Authorization IDs and dynamic SQL . . . . . . . . . . . . . . . . . . . . . . . . . . 73Authorization IDs and remote execution. . . . . . . . . . . . . . . . . . . . . . . . . 75

    Data types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78Nulls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79Character strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82Graphic strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92Binary strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93Large objects (LOBs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94Datetime values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96Row ID values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103XML values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104

    Distinct types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105Promotion of data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106Casting between data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107

    Implicit cast from numeric data to string data . . . . . . . . . . . . . . . . . . . . . . 115Implicit cast from string data to numeric data . . . . . . . . . . . . . . . . . . . . . . 115

    Assignment and comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117Numeric assignments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121String assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125Datetime assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128Row ID assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129XML assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129Distinct type assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129Assignments to LOB locators . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131Numeric comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131String comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132Datetime comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133Row ID comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134XML comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135Conversion rules for comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . 135Distinct type comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139

    Rules for result data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141Numeric operands. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141

    iv SQL Reference

    ||

    |

    ||||

  • Character and graphic string operands . . . . . . . . . . . . . . . . . . . . . . . . . 142Binary string operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143Datetime operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143Row ID operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144XML operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144Distinct type operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144

    Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145Integer constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145Floating-point constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145Decimal constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145Decimal floating-point constants . . . . . . . . . . . . . . . . . . . . . . . . . . . 146Character string constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147Binary string constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147Datetime constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148Graphic string constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151

    Special registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153General rules for special registers. . . . . . . . . . . . . . . . . . . . . . . . . . . 155CURRENT APPLICATION ENCODING SCHEME . . . . . . . . . . . . . . . . . . . . . 157CURRENT CLIENT_ACCTNG . . . . . . . . . . . . . . . . . . . . . . . . . . . 158CURRENT CLIENT_APPLNAME . . . . . . . . . . . . . . . . . . . . . . . . . . 159CURRENT CLIENT_USERID . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161CURRENT CLIENT_WRKSTNNAME . . . . . . . . . . . . . . . . . . . . . . . . . 162CURRENT DATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164CURRENT DEBUG MODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165CURRENT DECFLOAT ROUNDING MODE . . . . . . . . . . . . . . . . . . . . . . . 166CURRENT DEGREE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168CURRENT EXPLAIN MODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169CURRENT GET_ACCEL_ARCHIVE . . . . . . . . . . . . . . . . . . . . . . . . . . 171CURRENT LOCALE LC_CTYPE . . . . . . . . . . . . . . . . . . . . . . . . . . . 172CURRENT MAINTAINED TABLE TYPES FOR OPTIMIZATION . . . . . . . . . . . . . . . . 174CURRENT MEMBER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175CURRENT OPTIMIZATION HINT . . . . . . . . . . . . . . . . . . . . . . . . . . 176CURRENT PACKAGE PATH . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177CURRENT PACKAGESET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178CURRENT PATH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179CURRENT PRECISION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180CURRENT QUERY ACCELERATION . . . . . . . . . . . . . . . . . . . . . . . . . 181CURRENT REFRESH AGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183CURRENT ROUTINE VERSION . . . . . . . . . . . . . . . . . . . . . . . . . . . 184CURRENT RULES. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185CURRENT SCHEMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187CURRENT SERVER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188CURRENT SQLID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189CURRENT TIME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190CURRENT TIMESTAMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191CURRENT TIME ZONE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192ENCRYPTION PASSWORD . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193SESSION_USER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194SESSION TIME ZONE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195USER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196Special registers in a user-defined function or a stored procedure . . . . . . . . . . . . . . . . 197

    Column names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200Qualified column names. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200Correlation names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200Column name qualifiers to avoid ambiguity . . . . . . . . . . . . . . . . . . . . . . . 201Column name qualifiers in correlated references. . . . . . . . . . . . . . . . . . . . . . 203Resolution of column name qualifiers and column names . . . . . . . . . . . . . . . . . . 204

    References to variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206References to host variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206Host variables in dynamic SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . 209References to LOB host variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 210

    Contents v

    ||||

    ||

    ||

  • References to LOB locator variables . . . . . . . . . . . . . . . . . . . . . . . . . . 210References to XML host variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 211References to file reference variables. . . . . . . . . . . . . . . . . . . . . . . . . . 212References to stored procedure result sets . . . . . . . . . . . . . . . . . . . . . . . . 213References to result set locator variables . . . . . . . . . . . . . . . . . . . . . . . . 214References to built-in session variables . . . . . . . . . . . . . . . . . . . . . . . . . 215

    Host structures in PL/I, C, and COBOL . . . . . . . . . . . . . . . . . . . . . . . . . 218Host-variable-arrays in PL/I, C, C++, and COBOL . . . . . . . . . . . . . . . . . . . . . . 219Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220

    Types of functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220Function invocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222Function resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223

    Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229Expressions without operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . 231Expressions with arithmetic operators . . . . . . . . . . . . . . . . . . . . . . . . . 231Expressions with the concatenation operator . . . . . . . . . . . . . . . . . . . . . . . 238Scalar-fullselect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241Datetime operands and durations . . . . . . . . . . . . . . . . . . . . . . . . . . 242Time zone specific expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . 243Datetime arithmetic in SQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245Precedence of operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249CASE expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251CAST specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255XMLCAST specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264OLAP specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266ROW CHANGE expression. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273Sequence reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275

    Predicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280Basic predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282Quantified predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284BETWEEN predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287DISTINCT predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288EXISTS predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290IN predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292LIKE predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295NULL predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301XMLEXISTS predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302

    Search conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305Options affecting SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306

    SQL processing options for dynamic statements . . . . . . . . . . . . . . . . . . . . . . 308DECFLOAT rounding mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309Decimal point representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309Apostrophes and quotation marks as string delimiters. . . . . . . . . . . . . . . . . . . . 311Katakana characters for EBCDIC . . . . . . . . . . . . . . . . . . . . . . . . . . . 312Mixed data in character strings . . . . . . . . . . . . . . . . . . . . . . . . . . . 312Formatting of datetime strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . 313SQL standard language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313Positioned updates of columns . . . . . . . . . . . . . . . . . . . . . . . . . . . 314

    Mappings from SQL to XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315Mapping SQL character sets to XML character sets . . . . . . . . . . . . . . . . . . . . . 315Mapping SQL identifiers to XML names . . . . . . . . . . . . . . . . . . . . . . . . 315Mapping SQL data values to XML data values . . . . . . . . . . . . . . . . . . . . . . 315

    Chapter 3. Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317Aggregate functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325

    AVG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327CORRELATION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328COUNT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329COUNT_BIG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330COVARIANCE or COVARIANCE_SAMP . . . . . . . . . . . . . . . . . . . . . . . . 332MAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333

    vi SQL Reference

    ||

  • MIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334STDDEV or STDDEV_SAMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335SUM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337VARIANCE or VARIANCE_SAMP . . . . . . . . . . . . . . . . . . . . . . . . . . 338XMLAGG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340

    Scalar functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342ABS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343ACOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344ADD_MONTHS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345ASCII . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347ASCII_CHR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348ASCII_STR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349ASIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350ATAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351ATANH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352ATAN2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353BIGINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354BINARY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356BITAND, BITANDNOT, BITOR, BITXOR, and BITNOT . . . . . . . . . . . . . . . . . . . 358BLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360CCSID_ENCODING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362CEILING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363CHAR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364CHARACTER_LENGTH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373CLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375COALESCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378COLLATION_KEY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380COMPARE_DECFLOAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383CONCAT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385CONTAINS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386COS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389COSH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390DATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391DAY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393DAYOFMONTH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395DAYOFWEEK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396DAYOFWEEK_ISO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398DAYOFYEAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400DAYS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401DBCLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402DECFLOAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406DECFLOAT_FORMAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408DECFLOAT_SORTKEY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411DECIMAL or DEC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413DECODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415DECRYPT_BINARY, DECRYPT_BIT, DECRYPT_CHAR, and DECRYPT_DB . . . . . . . . . . . . 417DEGREES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421DIFFERENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422DIGITS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423DOUBLE_PRECISION or DOUBLE . . . . . . . . . . . . . . . . . . . . . . . . . . 424DSN_XMLVALIDATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426EBCDIC_CHR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428EBCDIC_STR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429ENCRYPT_TDES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430EXP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433EXTRACT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434FLOAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438FLOOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439GENERATE_UNIQUE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440GETHINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442GETVARIABLE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443

    Contents vii

    ||

    ||

    ||

  • GRAPHIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445HEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449HOUR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450IDENTITY_VAL_LOCAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452IFNULL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457INSERT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458INTEGER or INT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462JULIAN_DAY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464LAST_DAY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466LCASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468LEFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469LENGTH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473LN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475LOCATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476LOCATE_IN_STRING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479LOG10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482LOWER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483LPAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486LTRIM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488MAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490MICROSECOND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491MIDNIGHT_SECONDS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493MIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495MINUTE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496MOD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498MONTH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500MONTHS_BETWEEN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 502MQREAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504MQREADCLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506MQRECEIVE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508MQRECEIVECLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 510MQSEND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512MULTIPLY_ALT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515NEXT_DAY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516NORMALIZE_DECFLOAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518NORMALIZE_STRING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519NULLIF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521NVL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522OVERLAY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523PACK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527POSITION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 530POSSTR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533POWER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535QUANTIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536QUARTER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538RADIANS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540RAISE_ERROR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541RAND. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542REAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543REPEAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545REPLACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547RID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550RIGHT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551ROUND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553ROUND_TIMESTAMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 555ROWID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558RPAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 559RTRIM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561SCORE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563SECOND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566SIGN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568

    viii SQL Reference

    ||||

  • SIN. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569SINH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 570SMALLINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571SOUNDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573SOAPHTTPC and SOAPHTTPV . . . . . . . . . . . . . . . . . . . . . . . . . . . 574SOAPHTTPNC and SOAPHTTPNV . . . . . . . . . . . . . . . . . . . . . . . . . . 576SPACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578SQRT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579STRIP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580SUBSTR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 581SUBSTRING. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 584TAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590TANH. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591TIME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592TIMESTAMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593TIMESTAMPADD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596TIMESTAMP_FORMAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 598TIMESTAMP_ISO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604TIMESTAMPDIFF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605TIMESTAMP_TZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 608TO_CHAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610TO_DATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611TO_NUMBER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612TOTALORDER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 613TRANSLATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615TRIM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619TRUNCATE or TRUNC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621TRUNC_TIMESTAMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623UCASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626UNICODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 627UNICODE_STR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628UPPER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 630VALUE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 632VARBINARY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633VARCHAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 635VARCHAR_FORMAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 642VARGRAPHIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 652VERIFY_GROUP_FOR_USER . . . . . . . . . . . . . . . . . . . . . . . . . . . . 656VERIFY_ROLE_FOR_USER. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 658VERIFY_TRUSTED_CONTEXT_ROLE_FOR_USER . . . . . . . . . . . . . . . . . . . . . 660WEEK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 662WEEK_ISO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 663XMLATTRIBUTES. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665XMLCOMMENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 666XMLCONCAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 667XMLDOCUMENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 668XMLELEMENT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669XMLFOREST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674XMLMODIFY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 677XMLNAMESPACES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 679XMLPARSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681XMLPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 683XMLQUERY. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 684XMLSERIALIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688XMLTEXT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 691XMLXSROBJECTID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 692XSLTRANSFORM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 693YEAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695

    Table functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 696ADMIN_TASK_LIST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 697ADMIN_TASK_OUTPUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 702

    Contents ix

    ||

    ||

    ||

    ||||||

    ||

    ||||

    ||

  • ADMIN_TASK_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 704MQREADALL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 708MQREADALLCLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 710MQRECEIVEALL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 712MQRECEIVEALLCLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715XMLTABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 718

    Row functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 722UNPACK. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 723

    Chapter 4. Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725Authorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 726subselect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728

    select-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 729from-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 737where-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 752group-by-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 754having-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 756order-by-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 758fetch-first-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 761Examples of subselects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763

    fullselect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 769Character conversion in set operations and concatenations . . . . . . . . . . . . . . . . . . 774Selecting the result CCSID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 775

    select-statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 777common-table-expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 778update-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 781read-only-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 783optimize-clause. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 784isolation-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 785queryno-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 787SKIP LOCKED DATA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 788Examples of select statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 789

    Chapter 5. Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 791How SQL statements are invoked . . . . . . . . . . . . . . . . . . . . . . . . . . . 797

    Embedding a statement in an application program . . . . . . . . . . . . . . . . . . . . . 797Dynamic preparation and execution . . . . . . . . . . . . . . . . . . . . . . . . . . 798Static invocation of a SELECT statement . . . . . . . . . . . . . . . . . . . . . . . . 799Dynamic invocation of a SELECT statement . . . . . . . . . . . . . . . . . . . . . . . 800Interactive invocation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 800SQL diagnostics information . . . . . . . . . . . . . . . . . . . . . . . . . . . . 801Detecting and processing error and warning conditions in host language applications . . . . . . . . . 801

    SQL comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 804ALLOCATE CURSOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 805ALTER DATABASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 807ALTER FUNCTION (external) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 810ALTER FUNCTION (inlined SQL scalar) . . . . . . . . . . . . . . . . . . . . . . . . . 829ALTER FUNCTION (compiled SQL scalar) . . . . . . . . . . . . . . . . . . . . . . . . 837ALTER FUNCTION (SQL table) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 865ALTER INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 873ALTER MASK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 892ALTER PERMISSION. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 894ALTER PROCEDURE (external) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 896ALTER PROCEDURE (SQL - external) . . . . . . . . . . . . . . . . . . . . . . . . . . 907ALTER PROCEDURE (SQL - native). . . . . . . . . . . . . . . . . . . . . . . . . . . 913ALTER SEQUENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 940ALTER STOGROUP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 946ALTER TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 949ALTER TABLESPACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1034ALTER TRIGGER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1054

    x SQL Reference

    ||||

    ||||||||

    ||

  • ALTER TRUSTED CONTEXT . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1057ALTER VIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1069ASSOCIATE LOCATORS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1071BEGIN DECLARE SECTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1075CALL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1077CLOSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1089COMMENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1091COMMIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1101CONNECT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1104CREATE ALIAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1111CREATE AUXILIARY TABLE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1114CREATE DATABASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1118CREATE FUNCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1121CREATE FUNCTION (external scalar) . . . . . . . . . . . . . . . . . . . . . . . . . . 1122CREATE FUNCTION (external table) . . . . . . . . . . . . . . . . . . . . . . . . . . 1147CREATE FUNCTION (sourced) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1165CREATE FUNCTION (inlined SQL scalar) . . . . . . . . . . . . . . . . . . . . . . . . 1179CREATE FUNCTION (compiled SQL scalar). . . . . . . . . . . . . . . . . . . . . . . . 1190CREATE FUNCTION (SQL table) . . . . . . . . . . . . . . . . . . . . . . . . . . . 1214CREATE GLOBAL TEMPORARY TABLE. . . . . . . . . . . . . . . . . . . . . . . . . 1224CREATE INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1230CREATE MASK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1261CREATE PERMISSION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1271CREATE PROCEDURE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1279CREATE PROCEDURE (external) . . . . . . . . . . . . . . . . . . . . . . . . . . . 1280CREATE PROCEDURE (SQL - external) . . . . . . . . . . . . . . . . . . . . . . . . . 1299CREATE PROCEDURE (SQL - native) . . . . . . . . . . . . . . . . . . . . . . . . . . 1311CREATE ROLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1333CREATE SEQUENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1334CREATE STOGROUP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1342CREATE SYNONYM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1345CREATE TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1347CREATE TABLESPACE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1414CREATE TRIGGER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1441CREATE TRUSTED CONTEXT . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1458CREATE TYPE (distinct) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1468CREATE VIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1476DECLARE CURSOR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1484DECLARE GLOBAL TEMPORARY TABLE . . . . . . . . . . . . . . . . . . . . . . . . 1496DECLARE STATEMENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1510DECLARE TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1511DECLARE VARIABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1518DELETE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1521DESCRIBE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1537DESCRIBE CURSOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1538DESCRIBE INPUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1540DESCRIBE OUTPUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1543DESCRIBE PROCEDURE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1550DESCRIBE TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1553DROP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1556END DECLARE SECTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1576EXCHANGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1577EXECUTE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1578EXECUTE IMMEDIATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1583EXPLAIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1586FETCH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1595FREE LOCATOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1622GET DIAGNOSTICS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1623GRANT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1640GRANT (collection privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1644GRANT (database privileges). . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1645

    Contents xi

    ||

    ||||

  • GRANT (function or procedure privileges) . . . . . . . . . . . . . . . . . . . . . . . . 1648GRANT (package privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1653GRANT (plan privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1656GRANT (schema privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1657GRANT (sequence privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1659GRANT (system privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1660GRANT (table or view privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . 1666GRANT (type or JAR file privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . 1670GRANT (use privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1672HOLD LOCATOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1674INCLUDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1676INSERT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1678LABEL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1698LOCK TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1700MERGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1703OPEN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1718PREPARE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1723REFRESH TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1745RELEASE (connection) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1747RELEASE SAVEPOINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1749RENAME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1750REVOKE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1754REVOKE (collection privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1761REVOKE (database privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1763REVOKE (function or procedure privileges) . . . . . . . . . . . . . . . . . . . . . . . . 1766REVOKE (package privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1773REVOKE (plan privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1776REVOKE (schema privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1778REVOKE (sequence privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1781REVOKE (system privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1783REVOKE (table or view privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . 1789REVOKE (type or JAR file privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . 1793REVOKE (use privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1796ROLLBACK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1799SAVEPOINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1802SELECT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1804SELECT INTO. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1805SET CONNECTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1809SET CURRENT APPLICATION ENCODING SCHEME . . . . . . . . . . . . . . . . . . . . 1811SET CURRENT DEBUG MODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1812SET CURRENT DECFLOAT ROUNDING MODE . . . . . . . . . . . . . . . . . . . . . . 1814SET CURRENT DEGREE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1816SET CURRENT EXPLAIN MODE . . . . . . . . . . . . . . . . . . . . . . . . . . . 1818SET CURRENT GET_ACCEL_ARCHIVE . . . . . . . . . . . . . . . . . . . . . . . . . 1820SET CURRENT LOCALE LC_CTYPE . . . . . . . . . . . . . . . . . . . . . . . . . . 1821SET CURRENT MAINTAINED TABLE TYPES FOR OPTIMIZATION . . . . . . . . . . . . . . . 1823SET CURRENT OPTIMIZATION HINT . . . . . . . . . . . . . . . . . . . . . . . . . 1825SET CURRENT PACKAGE PATH . . . . . . . . . . . . . . . . . . . . . . . . . . . 1826SET CURRENT PACKAGESET . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1830SET CURRENT PRECISION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1832SET CURRENT QUERY ACCELERATION . . . . . . . . . . . . . . . . . . . . . . . . 1833SET CURRENT REFRESH AGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1835SET CURRENT ROUTINE VERSION . . . . . . . . . . . . . . . . . . . . . . . . . . 1837SET CURRENT RULES. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1839SET CURRENT SQLID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1840SET ENCRYPTION PASSWORD . . . . . . . . . . . . . . . . . . . . . . . . . . . 1842SET host-variable assignment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1844SET PATH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1847SET SCHEMA. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1850SET SESSION TIME ZONE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1853SET transition-variable assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . 1854

    xii SQL Reference

    ||||

    ||

  • SIGNAL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1857TRUNCATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1858UPDATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1862VALUES. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1882VALUES INTO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1883WHENEVER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1886

    Chapter 6. SQL control statements for SQL routines . . . . . . . . . . . . . . . 1889References to SQL parameters and SQL variables . . . . . . . . . . . . . . . . . . . . . . 1890References to SQL condition names. . . . . . . . . . . . . . . . . . . . . . . . . . . 1891References to SQL cursor names. . . . . . . . . . . . . . . . . . . . . . . . . . . . 1891References to labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1891Nested compound statements and scope of names . . . . . . . . . . . . . . . . . . . . . 1892SQL-procedure-statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1894assignment-statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1897CALL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1899CASE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1901compound-statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1903FOR statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1912GET DIAGNOSTICS statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1914GOTO statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1915IF statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1917ITERATE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1918LEAVE statement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1920LOOP statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1922REPEAT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1924RESIGNAL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1926RETURN statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1929SIGNAL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1932WHILE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1936

    Appendix. Additional information for DB2 SQL . . . . . . . . . . . . . . . . . 1937Limits in DB2 for z/OS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1938Reserved schema names and reserved words . . . . . . . . . . . . . . . . . . . . . . . 1945

    Reserved schema names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1946Reserved words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1947

    Characteristics of SQL statements in DB2 for z/OS . . . . . . . . . . . . . . . . . . . . . 1951Actions allowed on SQL statements . . . . . . . . . . . . . . . . . . . . . . . . . 1952SQL statements allowed in external functions and stored procedures . . . . . . . . . . . . . . 1956

    SQL control statements for external SQL procedures . . . . . . . . . . . . . . . . . . . . . 1958References to SQL parameters and SQL variables . . . . . . . . . . . . . . . . . . . . . 1959SQL-procedure-statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1961assignment-statement (SQL control statements for external routines). . . . . . . . . . . . . . . 1962CALL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1964CASE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1966compound-statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1969GET DIAGNOSTICS statement . . . . . . . . . . . . . . . . . . . . . . . . . . . 1975GOTO statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1976IF statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1978ITERATE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1980LEAVE statement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1981LOOP statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1982REPEAT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1984RESIGNAL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1985RETURN statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1988SIGNAL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1990WHILE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1994

    SQL communication area (SQLCA) . . . . . . . . . . . . . . . . . . . . . . . . . . . 1995Description of SQLCA fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1996The included SQLCA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2001

    Contents xiii

  • The REXX SQLCA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2003SQL descriptor area (SQLDA) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2005

    Description of SQLDA fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2007Unrecognized and unsupported SQLTYPES . . . . . . . . . . . . . . . . . . . . . . . 2019The included SQLDA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2020Identifying an SQLDA in C or C++. . . . . . . . . . . . . . . . . . . . . . . . . . 2024The REXX SQLDA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2025

    DB2 catalog tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2027Table spaces and indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2029New and changed catalog tables . . . . . . . . . . . . . . . . . . . . . . . . . . 2041SYSIBM.IPLIST table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2045SYSIBM.IPNAMES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2046SYSIBM.LOCATIONS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2049SYSIBM.LULIST table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2051SYSIBM.LUMODES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2052SYSIBM.LUNAMES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2053SYSIBM.MODESELECT table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2056SYSIBM.SYSAUDITPOLICIES table. . . . . . . . . . . . . . . . . . . . . . . . . . 2057SYSIBM.SYSAUTOALERTS table . . . . . . . . . . . . . . . . . . . . . . . . . . 2061SYSIBM.SYSAUTOALERTS_OUT table . . . . . . . . . . . . . . . . . . . . . . . . 2063SYSIBM.SYSAUTORUNS_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . 2064SYSIBM.SYSAUTORUNS_HISTOU table . . . . . . . . . . . . . . . . . . . . . . . . 2065SYSIBM.SYSAUTOTIMEWINDOWS table . . . . . . . . . . . . . . . . . . . . . . . 2066SYSIBM.SYSAUXRELS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2067SYSIBM.SYSCHECKDEP table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2068SYSIBM.SYSCHECKS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2069SYSIBM.SYSCHECKS2 table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2070SYSIBM.SYSCOLAUTH table. . . . . . . . . . . . . . . . . . . . . . . . . . . . 2071SYSIBM.SYSCOLDIST table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2073SYSIBM.SYSCOLDISTSTATS table . . . . . . . . . . . . . . . . . . . . . . . . . . 2075SYSIBM.SYSCOLDIST_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . . 2077SYSIBM.SYSCOLSTATS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2079SYSIBM.SYSCOLUMNS table. . . . . . . . . . . . . . . . . . . . . . . . . . . . 2081SYSIBM.SYSCOLUMNS_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . 2092SYSIBM.SYSCONSTDEP table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2096SYSIBM.SYSCONTEXT table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2097SYSIBM.SYSCONTEXTAUTHIDS table . . . . . . . . . . . . . . . . . . . . . . . . 2099SYSIBM.SYSCONTROLS table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2100SYSIBM.SYSCOPY table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2102SYSIBM.SYSCTXTTRUSTATTRS table . . . . . . . . . . . . . . . . . . . . . . . . . 2112SYSIBM.SYSDATABASE table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2113SYSIBM.SYSDATATYPES table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2115SYSIBM.SYSDBAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2117SYSIBM.SYSDBRM table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2120SYSIBM.SYSDEPENDENCIES table. . . . . . . . . . . . . . . . . . . . . . . . . . 2122SYSIBM.SYSDUMMY1 table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2124SYSIBM.SYSDUMMYA table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2125SYSIBM.SYSDUMMYE table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2126SYSIBM.SYSDUMMYU table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2127SYSIBM.SYSENVIRONMENT table. . . . . . . . . . . . . . . . . . . . . . . . . . 2128SYSIBM.SYSFIELDS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2130SYSIBM.SYSFOREIGNKEYS table . . . . . . . . . . . . . . . . . . . . . . . . . . 2132SYSIBM.SYSINDEXES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2133SYSIBM.SYSINDEXES_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . . 2139SYSIBM.SYSINDEXES_RTSECT table . . . . . . . . . . . . . . . . . . . . . . . . . 2141SYSIBM.SYSINDEXES_TREE table . . . . . . . . . . . . . . . . . . . . . . . . . . 2142SYSIBM.SYSINDEXPART table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2143SYSIBM.SYSINDEXPART_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . 2147SYSIBM.SYSINDEXSPACESTATS table . . . . . . . . . . . . . . . . . . . . . . . . 2150SYSIBM.SYSINDEXSTATS table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2156SYSIBM.SYSINDEXSTATS_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . 2158

    xiv SQL Reference

    ||||||||||||

    ||

    ||||||

    ||||

  • SYSIBM.SYSJARCLASS_SOURCE table . . . . . . . . . . . . . . . . . . . . . . . . 2160SYSIBM.SYSJARCONTENTS table . . . . . . . . . . . . . . . . . . . . . . . . . . 2161SYSIBM.SYSJARDATA table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2162SYSIBM.SYSJAROBJECTS table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2163SYSIBM.SYSJAVAOPTS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2164SYSIBM.SYSJAVAPATHS table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2165SYSIBM.SYSKEYCOLUSE table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2166SYSIBM.SYSKEYS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2167SYSIBM.SYSKEYTARGETS table. . . . . . . . . . . . . . . . . . . . . . . . . . . 2168SYSIBM.SYSKEYTARGETSTATS table . . . . . . . . . . . . . . . . . . . . . . . . . 2172SYSIBM.SYSKEYTARGETS_HIST table . . . . . . . . . . . . . . . . . . . . . . . . 2174SYSIBM.SYSKEYTGTDIST table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2177SYSIBM.SYSKEYTGTDISTSTATS table. . . . . . . . . . . . . . . . . . . . . . . . . 2179SYSIBM.SYSKEYTGTDIST_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . 2181SYSIBM.SYSLOBSTATS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2183SYSIBM.SYSLOBSTATS_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . . 2184SYSIBM.SYSOBJROLEDEP table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2185SYSIBM.SYSPACKAGE table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2186SYSIBM.SYSPACKCOPY table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2195SYSIBM.SYSPACKAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2204SYSIBM.SYSPACKDEP table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2206SYSIBM.SYSPACKLIST table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2208SYSIBM.SYSPACKSTMT table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2209SYSIBM.SYSPACKSTMT_STMB table . . . . . . . . . . . . . . . . . . . . . . . . . 2213SYSIBM.SYSPACKSTMT_STMT table . . . . . . . . . . . . . . . . . . . . . . . . . 2214SYSIBM.SYSPARMS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2215SYSIBM.SYSPENDINGDDL table . . . . . . . . . . . . . . . . . . . . . . . . . . 2219SYSIBM.SYSPENDINGOBJECTS table . . . . . . . . . . . . . . . . . . . . . . . . . 2220SYSIBM.SYSPKSYSTEM table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2221SYSIBM.SYSPLAN table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2223SYSIBM.SYSPLANAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2228SYSIBM.SYSPLANDEP table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2230SYSIBM.SYSPLSYSTEM table. . . . . . . . . . . . . . . . . . . . . . . . . . . . 2231SYSIBM.SYSQUERY table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2232SYSIBM.SYSQUERY_AUX table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2234SYSIBM.SYSQUERYOPTS table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2235SYSIBM.SYSQUERYPLAN table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2237SYSIBM.SYSRELS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2247SYSIBM.SYSRESAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2249SYSIBM.SYSROLES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2251SYSIBM.SYSROUTINEAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . 2252SYSIBM.SYSROUTINES table. . . . . . . . . . . . . . . . . . . . . . . . . . . . 2254SYSIBM.SYSROUTINESTEXT table . . . . . . . . . . . . . . . . . . . . . . . . . . 2265SYSIBM.SYSROUTINES_OPTS table . . . . . . . . . . . . . . . . . . . . . . . . . 2266SYSIBM.SYSROUTINES_TREE table . . . . . . . . . . . . . . . . . . . . . . . . . 2268SYSIBM.SYSROUTINES_SRC table . . . . . . . . . . . . . . . . . . . . . . . . . . 2269SYSIBM.SYSSCHEMAAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . 2270SYSIBM.SYSSEQUENCEAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . 2272SYSIBM.SYSSEQUENCES table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2274SYSIBM.SYSSEQUENCESDEP table . . . . . . . . . . . . . . . . . . . . . . . . . 2276SYSIBM.SYSSTMT table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2277SYSIBM.SYSSTOGROUP table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2281SYSIBM.SYSSTRINGS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2283SYSIBM.SYSSYNONYMS table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2286SYSIBM.SYSTABAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2287SYSIBM.SYSTABCONST table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2290SYSIBM.SYSTABLEPART table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2291SYSIBM.SYSTABLEPART_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . 2297SYSIBM.SYSTABLES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2300SYSIBM.SYSTABLESPACE table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2308SYSIBM.SYSTABLESPACESTATS table. . . . . . . . . . . . . . . . . . . . . . . . . 2314

    Contents xv

    ||

    ||||||||

    ||||||||

    ||

  • SYSIBM.SYSTABLES_HIST table. . . . . . . . . . . . . . . . . . . . . . . . . . . 2319SYSIBM.SYSTABLES_PROFILES table . . . . . . . . . . . . . . . . . . . . . . . . . 2321SYSIBM.SYSTABLES_PROFILE_TEXT table . . . . . . . . . . . . . . . . . . . . . . . 2322SYSIBM.SYSTABSTATS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2323SYSIBM.SYSTABSTATS_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . . 2324SYSIBM.SYSTRIGGERS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2325SYSIBM.SYSTRIGGERS_STMT table . . . . . . . . . . . . . . . . . . . . . . . . . 2327SYSIBM.SYSUSERAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2328SYSIBM.SYSVIEWDEP table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2332SYSIBM.SYSVIEWS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2333SYSIBM.SYSVIEWS_STMT table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2335SYSIBM.SYSVIEWS_TREE table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2336SYSIBM.SYSVOLUMES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2337SYSIBM.SYSXMLRELS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2338SYSIBM.SYSXMLSTRINGS table. . . . . . . . . . . . . . . . . . . . . . . . . . . 2339SYSIBM.USERNAMES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2340SYSIBM.SYSXMLTYPMOD table . . . . . . . . . . . . . . . . . . . . . . . . . . 2341SYSIBM.SYSXMLTYPMSCHEMA table . . . . . . . . . . . . . . . . . . . . . . . . 2342

    DB2 directory tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2343Directory table spaces and indexes . . . . . . . . . . . . . . . . . . . . . . . . . . 2344SYSIBM.DBDR table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2345SYSIBM.SYSDBD_DATA table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2346SYSIBM.SPTR table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2347SYSIBM.SYSSPTSEC_DATA table . . . . . . . . . . . . . . . . . . . . . . . . . . 2348SYSIBM.SYSSPTSEC_EXPL table . . . . . . . . . . . . . . . . . . . . . . . . . . 2349SYSIBM.SYSLGRNX table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2350SYSIBM.SYSUTIL table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2351SYSIBM.SYSUTILX table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2353

    Performance information for SQL application programming . . . . . . . . . . . . . . . . . . 2353DB2 XML schema repository tables. . . . . . . . . . . . . . . . . . . . . . . . . . . 2355

    XML schema repository (XSR) table spaces and indexes . . . . . . . . . . . . . . . . . . . 2356SYSIBM.XSRCOMPONENT table . . . . . . . . . . . . . . . . . . . . . . . . . . 2357SYSIBM.XSROBJECTS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2358SYSIBM.XSROBJECTCOMPONENTS table . . . . . . . . . . . . . . . . . . . . . . . 2360SYSIBM.XSROBJECTGRAMMAR table . . . . . . . . . . . . . . . . . . . . . . . . 2361SYSIBM.XSROBJECTHIERARCHIES table . . . . . . . . . . . . . . . . . . . . . . . 2362SYSIBM.XSROBJECTPROPERTY table . . . . . . . . . . . . . . . . . . . . . . . . . 2363SYSIBM.XSRPROPERTY table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2364

    EXPLAIN tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2365PLAN_TABLE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2366DSN_COLDIST_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2381DSN_DETCOST_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2387DSN_FILTER_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2396DSN_FUNCTION_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2400DSN_KEYTGTDIST_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2404DSN_PGRANGE_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2409DSN_PGROUP_TABLE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2412DSN_PREDICAT_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2417DSN_PTASK_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2423DSN_QUERYINFO_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2427DSN_QUERY_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2432DSN_SORTKEY_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2435DSN_SORT_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2439DSN_STATEMENT_CACHE_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . 2443DSN_STATEMNT_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2448DSN_STRUCT_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2453DSN_VIEWREF_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2457

    Tables that support query acceleration. . . . . . . . . . . . . . . . . . . . . . . . . . 2460SYSACCEL.SYSACCELERATORS table . . . . . . . . . . . . . . . . . . . . . . . . 2461SYSACCEL.SYSACCELERATEDTABLES table . . . . . . . . . . . . . . . . . . . . . . 2462SYSACCEL.SYSACCELERATEDPACKAGES table . . . . . . . . . . . . . . . . . . . . . 2464

    xvi SQL Reference

    ||||

    ||

    ||||

    ||||||||||||||||||||||||

    ||

    ||

    ||

  • Using the catalog in database design . . . . . . . . . . . . . . . . . . . . . . . . . . 2466Retrieving catalog information about DB2 storage groups . . . . . . . . . . . . . . . . . . 2467Retrieving catalog information about a table. . . . . . . . . . . . . . . . . . . . . . . 2467Retrieving catalog information about partition order . . . . . . . . . . . . . . . . . . . . 2468Retrieving catalog information about aliases. . . . . . . . . . . . . . . . . . . . . . . 2468Retrieving catalog information about columns . . . . . . . . . . . . . . . . . . . . . . 2469Retrieving catalog information about indexes . . . . . . . . . . . . . . . . . . . . . . 2470Retrieving catalog information about views . . . . . . . . . . . . . . . . . . . . . . . 2470Retrieving catalog information about authorizations . . . . . . . . . . . . . . . . . . . . 2471Retrieving catalog information about primary keys . . . . . . . . . . . . . . . . . . . . 2471Retrieving catalog information about foreign keys . . . . . . . . . . . . . . . . . . . . . 2472Retrieving catalog information about check pending . . . . . . . . . . . . . . . . . . . . 2473Retrieving catalog information about check constraints . . . . . . . . . . . . . . . . . . . 2473Retrieving catalog information about LOBs . . . . . . . . . . . . . . . . . . . . . . . 2474Retrieving catalog information about user-defined functions and stored procedures . . . . . . . . . 2475Retrieving catalog information about triggers . . . . . . . . . . . . . . . . . . . . . . 2475Retrieving catalog information about sequences . . . . . . . . . . . . . . . . . . . . . 2476Adding and retrieving comments . . . . . . . . . . . . . . . . . . . . . . . . . . 2476Verifying the accuracy of the database definition . . . . . . . . . . . . . . . . . . . . . 2477

    Sample user-defined functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2477ALTDATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2479ALTTIME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2482CURRENCY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2484DAYNAME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2486MONTHNAME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2487TABLE_LOCATION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2488TABLE_NAME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2490TABLE_SCHEMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2492WEATHER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2494

    Information resources for DB2 for z/OS and related products . . . . . . . . . . . 2497

    Notices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2499Programming interface information . . . . . . . . . . . . . . . . . . . . . . . . . . 2501Trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2501Privacy policy considerations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2502

    Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2503

    Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2505

    Contents xvii

  • xviii SQL Reference

  • About this informationThis book is a reference for Structured Query Language (SQL) for DB2 UniversalDatabase for z/OS. Unless otherwise stated, references to SQL in this bookimply SQL for DB2 UDB for z/OS, and all objects described in this book areobjects of DB2 UDB for z/OS.

    The syntax and semantics of most SQL statements are essentially the same in allIBM relational database products, and the language elements common to theproducts provide a base for the definition of IBM SQL. Consult IBM DB2 UniversalDatabase SQL Reference for Cross-Platform Development if you intend to developapplications that adhere to IBM SQL.

    This information assumes that your DB2 subsystem is running in Version 10new-function mode. Generally, new functions that are described, including changesto existing functions, statements, and limits, are available only in new-functionmode, unless explicitly stated otherwise. Exceptions to this general statementinclude optimization and virtual storage enhancements, which are also available inconversion mode unless stated otherwise. In Versions 8 and 9, most utilityfunctions were available in conversion mode. However, for Version 10, most utilityfunctions work only in new-function mode.

    Who should read this informationThis information is intended for end users, application programmers, system anddatabase administrators, and for persons involved in error detection and diagnosis.

    This information is a reference rather than a tutorial. It assumes that you arealready familiar with SQL programming concepts.

    When you first use this information, consider reading Chapters 1 and 2sequentially. These chapters describe the basic concepts of relational databases andSQL, the basic syntax of SQL, and the language elements that are common tomany SQL statements. The rest of the chapters and appendixes are designed forthe quick location of answers to specific SQL questions. They provide you withquery 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 asan optional product. You must separately order and purchase a license to suchutilities, and discussion of those utility functions in this publication is not intendedto otherwise imply that you have a license to them.

    The DB2 Utilities Suite can work with DB2 Sort and the DFSORT program. You arelicensed to use DFSORT in support of the DB2 utilities even if you do nototherwise license DFSORT for general use. If your primary sort product is notDFSORT, consider the following informational APARs mandatory reading:v II14047/II14213: USE OF DFSORT BY DB2 UTILITIESv II13495: HOW DFSORT TAKES ADVANTAGE OF 64-BIT REAL

    ARCHITECTURE

    Copyright IBM Corp. 1982, 2014 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 usesthe 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/OSv IBM Tivoli OMEGAMON XE for DB2 Performance Monitor on z/OSv IBM DB2 Performance Expert for Multiplatforms and Workgroupsv IBM DB2 Buffer Pool Analyzer for z/OS

    C, C++, and C languageRepresent 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 isequivalent to the Base Control Program (BCP) component of the z/OSoperating system.

    RACF

    Represents the functions that are provided by the RACF component of thez/OS Security Server.

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

    Accessibility features

    The 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 InformationCenter (which includes information for DB2 10 for z/OS) and its relatedpublications are accessibility-enabled for the IBM Home Page Reader. You canoperate all features using the keyboard instead of the mouse.

    Keyboard navigation

    You can access DB2 10 for z/OS ISPF panel functions by using a keyboard orkeyboard shortcut keys.

    xx SQL Reference

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

    Related accessibility information

    Online documentation for DB2 10 for z/OS is available in the InformationManagement Software for z/OS Solutions Information Center, which is available atthe following website: http://pic.dhe.ibm.com/infocenter/dzichelp/v2r2/index.jsp

    IBM and accessibility

    See the IBM Accessibility Center at http://www.ibm.com/able for more informationabout the commitment that IBM has to accessibility.

    How to send your commentsYour feedback helps IBM to provide quality information. Please send anycomments 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. Ifyou are commenting on specific text, please list the location of the text (forexample, 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 eachpage in the Information Management Software for z/OS Solutions InformationCenter at http://pic.dhe.ibm.com/infocenter/dzichelp/v2r2/index.jsp.

    About this information xxi

  • How to read syntax diagramsCertain conventions apply to the syntax diagrams that are used in IBMdocumentation.

    Apply the following rules when reading the syntax diagrams that are used in DB2for 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 nextline.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_itemoptional_item

    If an optional item appears above the main path, that item has no effect on theexecution 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 mainpath.

    required_item required_choice1required_choice2

    If choosing one of the items is optional, the entire stack appears below the mainpath.

    required_itemoptional_choice1optional_choice2

    If one of the items is the default, it appears above the main path and theremaining choices are shown below.

    required_itemdefault_choice

    optional_choiceoptional_choice

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

    xxii SQL Reference

  • required_item repeatable_item

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

    required_item

    ,

    repeatable_item

    A repeat arrow above a stack indicates that you can repeat the items in thestack.

    v Sometimes a diagram must be split into fragments. The syntax fragment isshown separately from the main syntax diagram, but the contents of thefragment should be read as if they are on the main path of the diagram.

    required_item fragment-name

    fragment-name:

    required_itemoptional_name

    v With the exception of XPath keywords, keywords appear in uppercase (forexample, FROM). Keywords must be spelled exactly as shown. XPath keywordsare defined as lowercase names, and must be spelled exactly as shown. Variablesappear in all lowercase letters (for example, column-name). They representuser-supplied names or values.

    v If punctuation marks, parentheses, arithmetic operators, or other such symbolsare 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 torepresent these values.

    At sites using a double-byte character set (DBCS), character strings can include amixture of single-byte and double-byte characters. When mixed data values areshown 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 - Part2: Foundation (SQL/Foundation)

    v ISO/IEC FCD 9075-3:2003, Information technology - Database languages - SQL - Part3: Call-Level Interface (SQL/CLI)

    v ISO/IEC FCD 9075-4:2003, Information technology - Database languages - SQL - Part4: Persistent Stored Modules (SQL/PSM)

    v ISO/IEC FCD 9075-5:2003, Information technology - Database languages - SQL- Part5: Host Language Bindings (SQL/Bindings)

    v ISO/IEC FCD 9075-9:2003, Information technology - Database languages - SQL - Part9: Management of External Data (SQL/MED)

    v ISO/IEC FCD 9075-10:2003, Information technology - Database languages - SQL - Part10: Object Language Bindings (SQL/OLB)

    v ISO/IEC FCD 9075-11:2003, Information technology - Database languages - SQL - Part11: Information and Definition Schemas (SQL/Schemata)

    v ISO/IEC FCD 9075-13:2003, Information technology - Database languages - SQL - Part13: Java Routines and Types (SQL/JRT)

    v ISO/IEC FCD 9075-14:2006, Information technology - Database languages - SQL - Part14: 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 QueryLanguage (SQL).

    The following topics provide information on these concepts:v Structured query languagev DB2 schemas and schema qualifiers on page 11v DB2 tables on page 6v DB2 indexes on page 6v DB2 keys on page 7v Constraints on page 23v Triggers on page 28v Storage structures on page 16v DB2 storage groups on page 13v DB2 databases on page 14v DB2 catalog on page 18v DB2 views on page 9v Sequences on page 34v Routines on page 32v Application processes, concurrency, and recovery on page 28v Packages and application plans on page 31v Distributed data on page 35v Character conversion on page 42

    Structured query languageThe language that you use to access the data in DB2 tables is the structured querylanguage (SQL). SQL is a standardized language for defining and manipulating datain a relational database.

    The language consists of SQL statements. SQL statements let you accomplish thefollowing 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 astables or views.

    When you write an SQL statement, you specify what you want done, not how todo it. To access data, for example, you need only to name the tables and columnsthat contain the data. You do not need to describe how to get to the data.

    In accordance with the relational model of data:v The database is perceived as a set of tables.v Relationships are represented by values in tables.

    Copyright IBM Corp. 1982, 2014 1

  • v Data is retrieved by using SQL to specify a result table that can be derived fromone or more tables.

    DB2 transforms each SQL statement, that is, the specification of a result table, intoa sequence of operations that optimize data retrieval. This transformation occurswhen the SQL statement is prepared. This transformation is also known as binding.

    All executable SQL statements must be prepared before they can run. The result ofpreparation is the executable or operational form of the statement.

    As the following example illustrates, SQL is generally intuitive.

    Example: Assume that you are shopping for shoes and you want to know whatshoe styles are available in size 8. The SQL query that you need to write is similarto the question that