2827
DB2 11 for z/OS SQL Reference SC19-4066-06

SQL Referencepublib.boulder.ibm.com/epubs/pdf/dsnsqn06.pdf · 2015-06-26 · SQL processing options for dynamic statements .....330 DECFLOAT rounding mode .....331 Decimal point representation

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

  • DB2 11 for z/OS

    SQL Reference

    SC19-4066-06

    ���

  • DB2 11 for z/OS

    SQL Reference

    SC19-4066-06

    ���

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

    Seventh edition (June 2015)

    This edition applies to DB2 11 for z/OS (product number 5615-DB2), DB2 11 for z/OS Value Unit Edition (productnumber 5697-P43), 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, 2015.US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contractwith IBM Corp.

  • Contents

    About this information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . xixWho should read this information . . . . . . . . . . . . . . . . . . . . . . . . . . . xixDB2 Utilities Suite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxTerminology and citations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxAccessibility features for DB2 11 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1SQL: the language of DB2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

    Ways to submit SQL statements to DB2 . . . . . . . . . . . . . . . . . . . . . . . . . 2DB2 data structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

    DB2 tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7DB2 indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7DB2 keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8DB2 views. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10DB2 schemas and schema qualifiers . . . . . . . . . . . . . . . . . . . . . . . . . . 12DB2 storage groups. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14DB2 databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

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

    DB2 hash spaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19DB2 system objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

    DB2 catalog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20DB2 directory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21Active and archive logs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21Bootstrap data set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Buffer pools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Data definition control support database . . . . . . . . . . . . . . . . . . . . . . . . 23The resource limit facility. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23Work file database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

    DB2 and data integrity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

    Application processes, concurrency, and recovery. . . . . . . . . . . . . . . . . . . . . . . 31Locking, commit, and rollback . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31Unit of work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31Unit of recovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32Rolling back work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32Packages and application plans . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

    Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35Stored procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

    Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36User-defined types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37Distributed data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

    Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38Distributed unit of work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39Remote unit of work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

    Character conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45Character sets and code pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47Coded character sets and CCSIDS . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

    © Copyright IBM Corp. 1982, 2015 iii

  • Determining the encoding scheme and CCSID of a string . . . . . . . . . . . . . . . . . . . 50Expanding conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54Contracting conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

    Chapter 2. Language elements . . . . . . . . . . . . . . . . . . . . . . . . . 55Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55Tokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

    SQL identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57Host identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59Restrictions for distributed access . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

    Naming conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59SQL path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66Resolution of unqualified object names . . . . . . . . . . . . . . . . . . . . . . . . . . 67Qualification of unqualified object names . . . . . . . . . . . . . . . . . . . . . . . . . 67

    Unqualified alias, index, JAR file, sequence, table, trigger, and view names . . . . . . . . . . . . . 68Unqualified type, function, procedure, global variable, and specific names . . . . . . . . . . . . . 68

    Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69Synonyms (deprecated) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70Authorization, privileges, permissions, masks, and object ownership . . . . . . . . . . . . . . . . 72Authorization IDs, roles, and authorization names . . . . . . . . . . . . . . . . . . . . . . 74

    Authorization IDs and schema names . . . . . . . . . . . . . . . . . . . . . . . . . 75Authorization IDs and statement preparation . . . . . . . . . . . . . . . . . . . . . . . 76Authorization IDs and dynamic SQL . . . . . . . . . . . . . . . . . . . . . . . . . . 77Authorization IDs and remote execution. . . . . . . . . . . . . . . . . . . . . . . . . 79

    Data types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82Nulls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83Character strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86Graphic strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96Binary strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97Large objects (LOBs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98Datetime values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100Row ID values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107XML values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108User-defined data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

    Promotion of data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112Casting between data types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

    Implicit cast from numeric data to string data . . . . . . . . . . . . . . . . . . . . . . 121Implicit cast from string data to numeric data . . . . . . . . . . . . . . . . . . . . . . 122

    Assignment and comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123Numeric assignments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124String assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129Datetime assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131Row ID assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133XML assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133User-defined type assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . 133Assignments to LOB locators . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136Numeric comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136String comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137Datetime comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139Row ID comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140XML comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140Conversion rules for comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . 140User-defined type comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . 145

    Rules for result data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146Numeric operands. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147Character and graphic string operands . . . . . . . . . . . . . . . . . . . . . . . . . 148Binary string operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149Datetime operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149Row ID operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

    iv SQL Reference

    |||||

    ||

    ||

    ||

  • XML operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150Distinct type operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

    Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150Integer constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151Floating-point constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151Decimal constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151Decimal floating-point constants . . . . . . . . . . . . . . . . . . . . . . . . . . . 152Character string constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152Binary string constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153Datetime constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154Graphic string constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157

    Special registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159General rules for special registers. . . . . . . . . . . . . . . . . . . . . . . . . . . 161Rules for setting special registers in profiles . . . . . . . . . . . . . . . . . . . . . . . 164CURRENT APPLICATION COMPATIBILITY . . . . . . . . . . . . . . . . . . . . . . . 166CURRENT APPLICATION ENCODING SCHEME . . . . . . . . . . . . . . . . . . . . . 167CURRENT CLIENT_ACCTNG . . . . . . . . . . . . . . . . . . . . . . . . . . . 168CURRENT CLIENT_APPLNAME . . . . . . . . . . . . . . . . . . . . . . . . . . 169CURRENT CLIENT_CORR_TOKEN. . . . . . . . . . . . . . . . . . . . . . . . . . 171CURRENT CLIENT_USERID . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172CURRENT CLIENT_WRKSTNNAME . . . . . . . . . . . . . . . . . . . . . . . . . 173CURRENT DATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175CURRENT DEBUG MODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176CURRENT DECFLOAT ROUNDING MODE . . . . . . . . . . . . . . . . . . . . . . . 177CURRENT DEGREE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179CURRENT EXPLAIN MODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180CURRENT GET_ACCEL_ARCHIVE . . . . . . . . . . . . . . . . . . . . . . . . . . 182CURRENT LOCALE LC_CTYPE . . . . . . . . . . . . . . . . . . . . . . . . . . . 183CURRENT MAINTAINED TABLE TYPES FOR OPTIMIZATION . . . . . . . . . . . . . . . . 185CURRENT MEMBER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186CURRENT OPTIMIZATION HINT . . . . . . . . . . . . . . . . . . . . . . . . . . 187CURRENT PACKAGE PATH . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188CURRENT PACKAGESET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189CURRENT PATH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190CURRENT PRECISION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191CURRENT QUERY ACCELERATION . . . . . . . . . . . . . . . . . . . . . . . . . 192CURRENT REFRESH AGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194CURRENT ROUTINE VERSION . . . . . . . . . . . . . . . . . . . . . . . . . . . 195CURRENT RULES. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196CURRENT SCHEMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198CURRENT SERVER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199CURRENT SQLID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200CURRENT TEMPORAL BUSINESS_TIME . . . . . . . . . . . . . . . . . . . . . . . . 201CURRENT TEMPORAL SYSTEM_TIME . . . . . . . . . . . . . . . . . . . . . . . . 203CURRENT TIME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205CURRENT TIMESTAMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206CURRENT TIME ZONE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207ENCRYPTION PASSWORD . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208SESSION_USER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209SESSION TIME ZONE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210USER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211Special registers in a user-defined function or a stored procedure . . . . . . . . . . . . . . . . 212

    Column names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215Qualified column names. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215Correlation names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216Column name qualifiers to avoid ambiguity . . . . . . . . . . . . . . . . . . . . . . . 216Column name qualifiers in correlated references. . . . . . . . . . . . . . . . . . . . . . 218Resolution of column name qualifiers and column names . . . . . . . . . . . . . . . . . . 219

    Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221Global variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222Host variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223

    Contents v

    ||||

    ||

    ||||

  • Variables in dynamic SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226LOB variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226LOB locator variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227XML variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227LOB or XML file reference variables . . . . . . . . . . . . . . . . . . . . . . . . . . 229Result set locator variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231Array variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231Host structures in PL/I, C, and COBOL . . . . . . . . . . . . . . . . . . . . . . . . 232Host variable arrays in PL/I, C, C++, and COBOL . . . . . . . . . . . . . . . . . . . . . 234

    Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234Types of functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234Function invocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236Function resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237

    Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243Expressions without operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . 246Expressions with arithmetic operators . . . . . . . . . . . . . . . . . . . . . . . . . 246Expressions with the concatenation operator . . . . . . . . . . . . . . . . . . . . . . . 253Scalar-fullselect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256Datetime operands and durations . . . . . . . . . . . . . . . . . . . . . . . . . . 257Time zone specific expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . 259Datetime arithmetic in SQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260Precedence of operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265CASE expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266CAST specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270XMLCAST specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279Array element specification. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281Array constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283OLAP specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285ROW CHANGE expression. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292Sequence reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294

    Predicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299Basic predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301Quantified predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303ARRAY_EXISTS predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306BETWEEN predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307DISTINCT predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308EXISTS predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310IN predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312LIKE predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315NULL predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323XMLEXISTS predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324

    Search conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327Options affecting SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328

    SQL processing options for dynamic statements . . . . . . . . . . . . . . . . . . . . . . 330DECFLOAT rounding mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331Decimal point representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331Apostrophes and quotation marks as string delimiters. . . . . . . . . . . . . . . . . . . . 333Katakana characters for EBCDIC . . . . . . . . . . . . . . . . . . . . . . . . . . . 334Mixed data in character strings . . . . . . . . . . . . . . . . . . . . . . . . . . . 334Formatting of datetime strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . 335SQL standard language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335Positioned updates of columns . . . . . . . . . . . . . . . . . . . . . . . . . . . 336

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

    Chapter 3. Built-in global variables and session variables . . . . . . . . . . . . . 339Built-in global variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340Built-in session variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342

    vi SQL Reference

    ||

    ||||

    ||

    ||

  • Chapter 4. Built-in functions . . . . . . . . . . . . . . . . . . . . . . . . . . 347Aggregate functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356

    ARRAY_AGG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358AVG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361CORRELATION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362COUNT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363COUNT_BIG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364COVARIANCE or COVARIANCE_SAMP . . . . . . . . . . . . . . . . . . . . . . . . 366GROUPING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367MAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369MEDIAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370MIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372STDDEV or STDDEV_SAMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373SUM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375VARIANCE or VARIANCE_SAMP . . . . . . . . . . . . . . . . . . . . . . . . . . 376XMLAGG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378

    Scalar functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380ABS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381ACOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382ADD_MONTHS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383ARRAY_DELETE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385ARRAY_FIRST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387ARRAY_LAST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389ARRAY_NEXT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391ARRAY_PRIOR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393ASCII . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395ASCII_CHR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396ASCII_STR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397ASIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398ATAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399ATANH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400ATAN2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401BIGINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402BINARY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404BITAND, BITANDNOT, BITOR, BITXOR, and BITNOT . . . . . . . . . . . . . . . . . . . 406BLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408CARDINALITY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410CCSID_ENCODING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411CEILING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412CHAR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413CHAR9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422CHARACTER_LENGTH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424CLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426COALESCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429COLLATION_KEY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431COMPARE_DECFLOAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434CONCAT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436CONTAINS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437COS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440COSH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441DATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442DAY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444DAYOFMONTH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446DAYOFWEEK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447DAYOFWEEK_ISO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449DAYOFYEAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451DAYS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452DBCLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453DECFLOAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457DECFLOAT_FORMAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459DECFLOAT_SORTKEY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462

    Contents vii

    ||

    ||

    ||

    ||||||||||

    ||

    ||

  • DECIMAL or DEC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464DECODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466DECRYPT_BINARY, DECRYPT_BIT, DECRYPT_CHAR, and DECRYPT_DB . . . . . . . . . . . . 468DEGREES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472DIFFERENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473DIGITS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474DOUBLE_PRECISION or DOUBLE . . . . . . . . . . . . . . . . . . . . . . . . . . 475DSN_XMLVALIDATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477EBCDIC_CHR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479EBCDIC_STR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480ENCRYPT_TDES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481EXP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484EXTRACT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485FLOAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489FLOOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490GENERATE_UNIQUE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491GETHINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493GETVARIABLE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494GRAPHIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496HEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500HOUR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501IDENTITY_VAL_LOCAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503IFNULL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508INSERT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509INTEGER or INT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513JULIAN_DAY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515LAST_DAY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517LCASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519LEFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520LENGTH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524LN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526LOCATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527LOCATE_IN_STRING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 530LOG10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533LOWER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534LPAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537LTRIM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539MAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541MAX_CARDINALITY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542MICROSECOND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543MIDNIGHT_SECONDS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545MIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547MINUTE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548MOD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550MONTH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552MONTHS_BETWEEN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 554MQREAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 556MQREADCLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558MQRECEIVE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 560MQRECEIVECLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 562MQSEND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 564MULTIPLY_ALT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567NEXT_DAY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568NORMALIZE_DECFLOAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 570NORMALIZE_STRING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571NULLIF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573NVL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574OVERLAY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575PACK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579POSITION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583POSSTR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586

    viii SQL Reference

    ||

  • POWER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589QUANTIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590QUARTER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592RADIANS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594RAISE_ERROR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595RAND. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596REAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597REPEAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599REPLACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 601RID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604RIGHT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605ROUND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 607ROUND_TIMESTAMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609ROWID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612RPAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 613RTRIM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615SCORE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617SECOND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 620SIGN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 622SIN. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623SINH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 624SMALLINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625SOUNDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 627SOAPHTTPC and SOAPHTTPV . . . . . . . . . . . . . . . . . . . . . . . . . . . 628SOAPHTTPNC and SOAPHTTPNV . . . . . . . . . . . . . . . . . . . . . . . . . . 630SPACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 632SQRT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633STRIP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634SUBSTR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 635SUBSTRING. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 638TAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 643TANH. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 644TIME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645TIMESTAMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 646TIMESTAMPADD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 649TIMESTAMP_FORMAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651TIMESTAMP_ISO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 657TIMESTAMPDIFF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 658TIMESTAMP_TZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 661TO_CHAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 663TO_DATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 664TO_NUMBER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665TOTALORDER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 666TRANSLATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 668TRIM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 672TRIM_ARRAY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674TRUNCATE or TRUNC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 675TRUNC_TIMESTAMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 677UCASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 680UNICODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681UNICODE_STR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 682UPPER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 684VALUE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 686VARBINARY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 687VARBINARY_FORMAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 689VARCHAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 691VARCHAR_BIT_FORMAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 698VARCHAR9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 700VARCHAR_FORMAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 702VARGRAPHIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 712VERIFY_GROUP_FOR_USER . . . . . . . . . . . . . . . . . . . . . . . . . . . . 716

    Contents ix

    ||

    ||

    ||||

  • VERIFY_ROLE_FOR_USER. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 718VERIFY_TRUSTED_CONTEXT_ROLE_FOR_USER . . . . . . . . . . . . . . . . . . . . . 720WEEK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 722WEEK_ISO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 723XMLATTRIBUTES. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725XMLCOMMENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 726XMLCONCAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 727XMLDOCUMENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728XMLELEMENT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 729XMLFOREST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 734XMLMODIFY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 737XMLNAMESPACES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 739XMLPARSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 741XMLPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 743XMLQUERY. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 744XMLSERIALIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 748XMLTEXT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 751XMLXSROBJECTID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 752XSLTRANSFORM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 753YEAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 755

    Table functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 756ADMIN_TASK_LIST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 757ADMIN_TASK_OUTPUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 762ADMIN_TASK_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764MQREADALL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 768MQREADALLCLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 770MQRECEIVEALL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 772MQRECEIVEALLCLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 775XMLTABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 778

    Row functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 782UNPACK. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 783

    Chapter 5. Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 785Authorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 786subselect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 788

    select-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 789from-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 797where-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 819group-by-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 821having-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 827order-by-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 828fetch-first-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 831Examples of subselects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 833Examples of grouping sets, rollup, and cube queries . . . . . . . . . . . . . . . . . . . . 839

    fullselect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 847Character conversion in set operations and concatenations . . . . . . . . . . . . . . . . . . 852Selecting the result CCSID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 853

    select-statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 855common-table-expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 856update-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 859read-only-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 860optimize-clause. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 861isolation-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 862queryno-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 864SKIP LOCKED DATA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 865Examples of SELECT statements . . . . . . . . . . . . . . . . . . . . . . . . . . . 866

    Chapter 6. Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 869How SQL statements are invoked . . . . . . . . . . . . . . . . . . . . . . . . . . . 874

    Embedding a statement in an application program . . . . . . . . . . . . . . . . . . . . . 875

    x SQL Reference

    ||

    ||

  • Dynamic preparation and execution . . . . . . . . . . . . . . . . . . . . . . . . . . 876Static invocation of a SELECT statement . . . . . . . . . . . . . . . . . . . . . . . . 877Dynamic invocation of a SELECT statement . . . . . . . . . . . . . . . . . . . . . . . 878Interactive invocation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 878SQL diagnostics information . . . . . . . . . . . . . . . . . . . . . . . . . . . . 879Detecting and processing error and warning conditions in host language applications . . . . . . . . . 879

    SQL comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 882ALLOCATE CURSOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 883ALTER DATABASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 885ALTER FUNCTION (external) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 888ALTER FUNCTION (compiled SQL scalar) . . . . . . . . . . . . . . . . . . . . . . . . 907ALTER FUNCTION (inlined SQL scalar) . . . . . . . . . . . . . . . . . . . . . . . . . 937ALTER FUNCTION (SQL table) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 945ALTER INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 953ALTER MASK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 972ALTER PERMISSION. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 974ALTER PROCEDURE (external) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 976ALTER PROCEDURE (SQL - external) . . . . . . . . . . . . . . . . . . . . . . . . . . 987ALTER PROCEDURE (SQL - native). . . . . . . . . . . . . . . . . . . . . . . . . . . 993ALTER SEQUENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1022ALTER STOGROUP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1028ALTER TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1031ALTER TABLESPACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1124ALTER TRIGGER. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1145ALTER TRUSTED CONTEXT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1148ALTER VIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1160ASSOCIATE LOCATORS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1162BEGIN DECLARE SECTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1166CALL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1168CLOSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1182COMMENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1184COMMIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1194CONNECT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1198CREATE ALIAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1205CREATE AUXILIARY TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1209CREATE DATABASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1213CREATE FUNCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1216CREATE FUNCTION (compiled SQL scalar) . . . . . . . . . . . . . . . . . . . . . . . 1217CREATE FUNCTION (external scalar) . . . . . . . . . . . . . . . . . . . . . . . . . . 1244CREATE FUNCTION (external table) . . . . . . . . . . . . . . . . . . . . . . . . . . 1269CREATE FUNCTION (inlined SQL scalar) . . . . . . . . . . . . . . . . . . . . . . . . 1288CREATE FUNCTION (sourced) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1299CREATE FUNCTION (SQL table) . . . . . . . . . . . . . . . . . . . . . . . . . . . 1313CREATE GLOBAL TEMPORARY TABLE. . . . . . . . . . . . . . . . . . . . . . . . . 1323CREATE INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1329CREATE MASK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1361CREATE PERMISSION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1372CREATE PROCEDURE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1380CREATE PROCEDURE (external) . . . . . . . . . . . . . . . . . . . . . . . . . . . 1381CREATE PROCEDURE (SQL - external) . . . . . . . . . . . . . . . . . . . . . . . . . 1400CREATE PROCEDURE (SQL - native) . . . . . . . . . . . . . . . . . . . . . . . . . . 1412CREATE ROLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1438CREATE SEQUENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1439CREATE STOGROUP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1447CREATE SYNONYM (deprecated) . . . . . . . . . . . . . . . . . . . . . . . . . . . 1450CREATE TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1452CREATE TABLESPACE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1524CREATE TRIGGER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1552CREATE TRUSTED CONTEXT . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1570CREATE TYPE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1580CREATE TYPE (array) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1581

    Contents xi

    ||||

  • CREATE TYPE (distinct) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1586CREATE VARIABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1594CREATE VIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1598DECLARE CURSOR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1606DECLARE GLOBAL TEMPORARY TABLE . . . . . . . . . . . . . . . . . . . . . . . . 1618DECLARE STATEMENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1633DECLARE TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1634DECLARE VARIABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1641DELETE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1644DESCRIBE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1661DESCRIBE CURSOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1662DESCRIBE INPUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1664DESCRIBE OUTPUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1667DESCRIBE PROCEDURE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1674DESCRIBE TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1677DROP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1680END DECLARE SECTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1703EXCHANGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1704EXECUTE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1705EXECUTE IMMEDIATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1711EXPLAIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1714FETCH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1723FREE LOCATOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1751GET DIAGNOSTICS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1752GRANT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1768GRANT (collection privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1772GRANT (database privileges). . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1773GRANT (function or procedure privileges) . . . . . . . . . . . . . . . . . . . . . . . . 1776GRANT (package privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1781GRANT (plan privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1784GRANT (schema privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1785GRANT (sequence privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1787GRANT (system privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1788GRANT (table or view privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . 1794GRANT (type or JAR file privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . 1798GRANT (variable privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1800GRANT (use privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1801HOLD LOCATOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1803INCLUDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1805INSERT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1807LABEL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1828LOCK TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1830MERGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1833OPEN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1848PREPARE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1854REFRESH TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1877RELEASE (connection) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1879RELEASE SAVEPOINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1881RENAME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1882REVOKE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1887REVOKE (collection privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1894REVOKE (database privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1896REVOKE (function or procedure privileges) . . . . . . . . . . . . . . . . . . . . . . . . 1899REVOKE (package privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1906REVOKE (plan privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1909REVOKE (schema privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1911REVOKE (sequence privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1914REVOKE (system privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1916REVOKE (table or view privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . 1922REVOKE (type or JAR file privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . 1926REVOKE (variable privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1929

    xii SQL Reference

    ||

    ||

    ||

  • REVOKE (use privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1931ROLLBACK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1934SAVEPOINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1938SELECT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1940SELECT INTO. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1941SET CONNECTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1947SET assignment-statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1950SET CURRENT APPLICATION COMPATIBILITY . . . . . . . . . . . . . . . . . . . . . . 1957SET CURRENT APPLICATION ENCODING SCHEME . . . . . . . . . . . . . . . . . . . . 1958SET CURRENT DEBUG MODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1959SET CURRENT DECFLOAT ROUNDING MODE . . . . . . . . . . . . . . . . . . . . . . 1961SET CURRENT DEGREE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1963SET CURRENT EXPLAIN MODE . . . . . . . . . . . . . . . . . . . . . . . . . . . 1965SET CURRENT GET_ACCEL_ARCHIVE . . . . . . . . . . . . . . . . . . . . . . . . . 1967SET CURRENT LOCALE LC_CTYPE . . . . . . . . . . . . . . . . . . . . . . . . . . 1968SET CURRENT MAINTAINED TABLE TYPES FOR OPTIMIZATION . . . . . . . . . . . . . . . 1970SET CURRENT OPTIMIZATION HINT . . . . . . . . . . . . . . . . . . . . . . . . . 1972SET CURRENT PACKAGE PATH . . . . . . . . . . . . . . . . . . . . . . . . . . . 1973SET CURRENT PACKAGESET . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1977SET CURRENT PRECISION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1979SET CURRENT QUERY ACCELERATION . . . . . . . . . . . . . . . . . . . . . . . . 1980SET CURRENT REFRESH AGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1982SET CURRENT ROUTINE VERSION . . . . . . . . . . . . . . . . . . . . . . . . . . 1984SET CURRENT RULES. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1986SET CURRENT SQLID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1987SET CURRENT TEMPORAL BUSINESS_TIME . . . . . . . . . . . . . . . . . . . . . . . 1989SET CURRENT TEMPORAL SYSTEM_TIME . . . . . . . . . . . . . . . . . . . . . . . 1991SET ENCRYPTION PASSWORD . . . . . . . . . . . . . . . . . . . . . . . . . . . 1993SET PATH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1995SET SCHEMA. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1998SET SESSION TIME ZONE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2001SIGNAL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2002TRUNCATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2003UPDATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2007VALUES. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2029VALUES INTO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2030WHENEVER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2035

    Chapter 7. SQL control statements for SQL routines . . . . . . . . . . . . . . . 2037References to SQL parameters and SQL variables . . . . . . . . . . . . . . . . . . . . . . 2038References to SQL condition names. . . . . . . . . . . . . . . . . . . . . . . . . . . 2039References to SQL cursor names. . . . . . . . . . . . . . . . . . . . . . . . . . . . 2039References to labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2039References to SQL statement names . . . . . . . . . . . . . . . . . . . . . . . . . . 2040Nested compound statements and scope of names . . . . . . . . . . . . . . . . . . . . . 2040SQL-procedure-statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2042assignment-statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2046CALL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2048CASE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2050compound-statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2052FOR statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2061GET DIAGNOSTICS statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2063GOTO statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2064IF statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2066ITERATE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2067LEAVE statement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2069LOOP statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2071REPEAT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2073RESIGNAL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2075RETURN statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2078SIGNAL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2081

    Contents xiii

    ||||

    ||||

    ||

  • WHILE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2085

    Appendix. Additional information for DB2 SQL . . . . . . . . . . . . . . . . . 2087Limits in DB2 for z/OS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2088Reserved schema names and reserved words . . . . . . . . . . . . . . . . . . . . . . . 2095

    Reserved schema names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2096Reserved words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2097

    Characteristics of SQL statements in DB2 for z/OS . . . . . . . . . . . . . . . . . . . . . 2101Actions allowed on SQL statements . . . . . . . . . . . . . . . . . . . . . . . . . 2102SQL statements allowed in functions and stored procedures . . . . . . . . . . . . . . . . . 2106

    SQL control statements for external SQL procedures . . . . . . . . . . . . . . . . . . . . . 2108References to SQL parameters and SQL variables . . . . . . . . . . . . . . . . . . . . . 2109SQL-procedure-statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2110assignment-statement (SQL control statements for external routines) . . . . . . . . . . . . . . . 2111CALL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2113CASE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2115compound-statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2118GET DIAGNOSTICS statement . . . . . . . . . . . . . . . . . . . . . . . . . . . 2124GOTO statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2125IF statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2127ITERATE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2129LEAVE statement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2130LOOP statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2131REPEAT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2133RESIGNAL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2134RETURN statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2137SIGNAL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2139WHILE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2143

    SQL communication area (SQLCA) . . . . . . . . . . . . . . . . . . . . . . . . . . . 2144Description of SQLCA fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2145The included SQLCA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2150The REXX SQLCA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2152

    SQL descriptor area (SQLDA) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2154Description of SQLDA fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2156Unrecognized and unsupported SQLTYPES . . . . . . . . . . . . . . . . . . . . . . . 2169The included SQLDA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2170Identifying an SQLDA in C or C++. . . . . . . . . . . . . . . . . . . . . . . . . . 2174The REXX SQLDA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2175

    DB2 catalog tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2177Table spaces and indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2179New and changed catalog tables . . . . . . . . . . . . . . . . . . . . . . . . . . 2191SYSIBM.IPLIST table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2194SYSIBM.IPNAMES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2195SYSIBM.LOCATIONS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2198SYSIBM.LULIST table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2200SYSIBM.LUMODES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2201SYSIBM.LUNAMES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2202SYSIBM.MODESELECT table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2205SYSIBM.SYSAUDITPOLICIES table. . . . . . . . . . . . . . . . . . . . . . . . . . 2206SYSIBM.SYSAUTOALERTS table . . . . . . . . . . . . . . . . . . . . . . . . . . 2210SYSIBM.SYSAUTOALERTS_OUT table . . . . . . . . . . . . . . . . . . . . . . . . 2212SYSIBM.SYSAUTORUNS_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . 2213SYSIBM.SYSAUTORUNS_HISTOU table . . . . . . . . . . . . . . . . . . . . . . . . 2214SYSIBM.SYSAUTOTIMEWINDOWS table . . . . . . . . . . . . . . . . . . . . . . . 2215SYSIBM.SYSAUXRELS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2216SYSIBM.SYSCHECKDEP table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2217SYSIBM.SYSCHECKS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2218SYSIBM.SYSCHECKS2 table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2219SYSIBM.SYSCOLAUTH table. . . . . . . . . . . . . . . . . . . . . . . . . . . . 2220SYSIBM.SYSCOLDIST table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2222SYSIBM.SYSCOLDISTSTATS table . . . . . . . . . . . . . . . . . . . . . . . . . . 2224

    xiv SQL Reference

  • SYSIBM.SYSCOLDIST_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . . 2226SYSIBM.SYSCOLSTATS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2228SYSIBM.SYSCOLUMNS table. . . . . . . . . . . . . . . . . . . . . . . . . . . . 2230SYSIBM.SYSCOLUMNS_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . 2241SYSIBM.SYSCONSTDEP table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2245SYSIBM.SYSCONTEXT table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2246SYSIBM.SYSCONTEXTAUTHIDS table . . . . . . . . . . . . . . . . . . . . . . . . 2248SYSIBM.SYSCONTROLS table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2249SYSIBM.SYSCOPY table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2251SYSIBM.SYSCTXTTRUSTATTRS table . . . . . . . . . . . . . . . . . . . . . . . . . 2264SYSIBM.SYSDATABASE table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2265SYSIBM.SYSDATATYPES table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2267SYSIBM.SYSDBAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2269SYSIBM.SYSDBRM table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2272SYSIBM.SYSDEPENDENCIES table. . . . . . . . . . . . . . . . . . . . . . . . . . 2274SYSIBM.SYSDUMMY1 table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2277SYSIBM.SYSDUMMYA table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2278SYSIBM.SYSDUMMYE table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2279SYSIBM.SYSDUMMYU table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2280SYSIBM.SYSENVIRONMENT table. . . . . . . . . . . . . . . . . . . . . . . . . . 2281SYSIBM.SYSFIELDS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2283SYSIBM.SYSFOREIGNKEYS table . . . . . . . . . . . . . . . . . . . . . . . . . . 2285SYSIBM.SYSINDEXCLEANUP table . . . . . . . . . . . . . . . . . . . . . . . . . 2286SYSIBM.SYSINDEXES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2287SYSIBM.SYSINDEXES_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . . 2294SYSIBM.SYSINDEXES_RTSECT table . . . . . . . . . . . . . . . . . . . . . . . . . 2296SYSIBM.SYSINDEXES_TREE table . . . . . . . . . . . . . . . . . . . . . . . . . . 2297SYSIBM.SYSINDEXPART table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2298SYSIBM.SYSINDEXPART_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . 2303SYSIBM.SYSINDEXSPACESTATS table . . . . . . . . . . . . . . . . . . . . . . . . 2306SYSIBM.SYSINDEXSTATS table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2312SYSIBM.SYSINDEXSTATS_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . 2314SYSIBM.SYSJARCLASS_SOURCE table . . . . . . . . . . . . . . . . . . . . . . . . 2316SYSIBM.SYSJARCONTENTS table . . . . . . . . . . . . . . . . . . . . . . . . . . 2317SYSIBM.SYSJARDATA table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2318SYSIBM.SYSJAROBJECTS table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2319SYSIBM.SYSJAVAOPTS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2320SYSIBM.SYSJAVAPATHS table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2321SYSIBM.SYSKEYCOLUSE table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2322SYSIBM.SYSKEYS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2323SYSIBM.SYSKEYTARGETS table. . . . . . . . . . . . . . . . . . . . . . . . . . . 2324SYSIBM.SYSKEYTARGETSTATS table . . . . . . . . . . . . . . . . . . . . . . . . . 2328SYSIBM.SYSKEYTARGETS_HIST table . . . . . . . . . . . . . . . . . . . . . . . . 2330SYSIBM.SYSKEYTGTDIST table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2333SYSIBM.SYSKEYTGTDISTSTATS table. . . . . . . . . . . . . . . . . . . . . . . . . 2335SYSIBM.SYSKEYTGTDIST_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . 2337SYSIBM.SYSLOBSTATS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2339SYSIBM.SYSLOBSTATS_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . . 2340SYSIBM.SYSOBJROLEDEP table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2341SYSIBM.SYSPACKAGE table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2342SYSIBM.SYSPACKCOPY table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2352SYSIBM.SYSPACKAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2362SYSIBM.SYSPACKDEP table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2364SYSIBM.SYSPACKLIST table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2366SYSIBM.SYSPACKSTMT table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2367SYSIBM.SYSPACKSTMT_STMB table . . . . . . . . . . . . . . . . . . . . . . . . . 2372SYSIBM.SYSPACKSTMT_STMT table . . . . . . . . . . . . . . . . . . . . . . . . . 2373SYSIBM.SYSPARMS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2374SYSIBM.SYSPENDINGDDL table . . . . . . . . . . . . . . . . . . . . . . . . . . 2378SYSIBM.SYSPENDINGOBJECTS table . . . . . . . . . . . . . . . . . . . . . . . . . 2380SYSIBM.SYSPKSYSTEM table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2381

    Contents xv

    ||

  • SYSIBM.SYSPLAN table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2383SYSIBM.SYSPLANAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2388SYSIBM.SYSPLANDEP table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2390SYSIBM.SYSPLSYSTEM table. . . . . . . . . . . . . . . . . . . . . . . . . . . . 2391SYSIBM.SYSQUERY table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2392SYSIBM.SYSQUERY_AUX table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2395SYSIBM.SYSQUERYOPTS table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2396SYSIBM.SYSQUERYPLAN table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2398SYSIBM.SYSQUERYPREDICATE table. . . . . . . . . . . . . . . . . . . . . . . . . 2409SYSIBM.SYSQUERYSEL table. . . . . . . . . . . . . . . . . . . . . . . . . . . . 2414SYSIBM.SYSRELS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2417SYSIBM.SYSRESAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2419SYSIBM.SYSROLES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2421SYSIBM.SYSROUTINEAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . 2422SYSIBM.SYSROUTINES table. . . . . . . . . . . . . . . . . . . . . . . . . . . . 2424SYSIBM.SYSROUTINESTEXT table . . . . . . . . . . . . . . . . . . . . . . . . . . 2434SYSIBM.SYSROUTINES_OPTS table . . . . . . . . . . . . . . . . . . . . . . . . . 2435SYSIBM.SYSROUTINES_TREE table . . . . . . . . . . . . . . . . . . . . . . . . . 2437SYSIBM.SYSROUTINES_SRC table . . . . . . . . . . . . . . . . . . . . . . . . . . 2438SYSIBM.SYSSCHEMAAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . 2439SYSIBM.SYSSEQUENCEAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . 2441SYSIBM.SYSSEQUENCES table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2443SYSIBM.SYSSEQUENCESDEP table . . . . . . . . . . . . . . . . . . . . . . . . . 2446SYSIBM.SYSSTATFEEDBACK table . . . . . . . . . . . . . . . . . . . . . . . . . . 2447SYSIBM.SYSSTMT table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2449SYSIBM.SYSSTOGROUP table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2453SYSIBM.SYSSTRINGS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2455SYSIBM.SYSSYNONYMS table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2458SYSIBM.SYSTABAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2459SYSIBM.SYSTABCONST table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2462SYSIBM.SYSTABLEPART table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2463SYSIBM.SYSTABLEPART_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . 2469SYSIBM.SYSTABLES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2472SYSIBM.SYSTABLESPACE table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2480SYSIBM.SYSTABLESPACESTATS table. . . . . . . . . . . . . . . . . . . . . . . . . 2486SYSIBM.SYSTABLES_HIST table. . . . . . . . . . . . . . . . . . . . . . . . . . . 2492SYSIBM.SYSTABLES_PROFILES table . . . . . . . . . . . . . . . . . . . . . . . . . 2494SYSIBM.SYSTABLES_PROFILE_TEXT table . . . . . . . . . . . . . . . . . . . . . . . 2495SYSIBM.SYSTABSTATS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2496SYSIBM.SYSTABSTATS_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . . 2498SYSIBM.SYSTRIGGERS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2499SYSIBM.SYSTRIGGERS_STMT table . . . . . . . . . . . . . . . . . . . . . . . . . 2501SYSIBM.SYSUSERAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2502SYSIBM.SYSVARIABLES table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2506SYSIBM.SYSVARIABLEAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . 2509SYSIBM.SYSVARIABLES_DESC table . . . . . . . . . . . . . . . . . . . . . . . . . 2511SYSIBM.SYSVARIABLES_TEXT table . . . . . . . . . . . . . . . . . . . . . . . . . 2512SYSIBM.SYSVIEWDEP table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2513SYSIBM.SYSVIEWS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2514SYSIBM.SYSVIEWS_STMT table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2516SYSIBM.SYSVIEWS_TREE table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2517SYSIBM.SYSVOLUMES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2518SYSIBM.SYSXMLRELS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2519SYSIBM.SYSXMLSTRINGS table. . . . . . . . . . . . . . . . . . . . . . . . . . . 2520SYSIBM.USERNAMES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2521SYSIBM.SYSXMLTYPMOD table . . . . . . . . . . . . . . . . . . . . . . . . . . 2522SYSIBM.SYSXMLTYPMSCHEMA table . . . . . . . . . . . . . . . . . . . . . . . . 2523

    DB2 directory tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2524Directory table spaces and indexes . . . . . . . . . . . . . . . . . . . . . . . . . . 2525SYSIBM.DBDR table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2526SYSIBM.SYSDBD_DATA table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2527

    xvi SQL Reference

    ||||

    ||

    ||||||||

  • SYSIBM.SCTR table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2528SYSIBM.SPTR table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2529SYSIBM.SYSSPTSEC_DATA table . . . . . . . . . . . . . . . . . . . . . . . . . . 2530SYSIBM.SYSSPTSEC_EXPL table . . . . . . . . . . . . . . . . . . . . . . . . . . 2531SYSIBM.SYSLGRNX table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2532SYSIBM.SYSUTIL table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2533SYSIBM.SYSUTILX table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2535

    Performance information for SQL application programming . . . . . . . . . . . . . . . . . . 2535DB2 XML schema repository tables. . . . . . . . . . . . . . . . . . . . . . . . . . . 2537

    XML schema repository (XSR) table spaces and indexes . . . . . . . . . . . . . . . . . . . 2538SYSIBM.XSRCOMPONENT table . . . . . . . . . . . . . . . . . . . . . . . . . . 2539SYSIBM.XSROBJECTS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2540SYSIBM.XSROBJECTCOMPONENTS table . . . . . . . . . . . . . . . . . . . . . . . 2542SYSIBM.XSROBJECTGRAMMAR table . . . . . . . . . . . . . . . . . . . . . . . . 2543SYSIBM.XSROBJECTHIERARCHIES table . . . . . . . . . . . . . . . . . . . . . . . 2544SYSIBM.XSROBJECTPROPERTY table . . . . . . . . . . . . . . . . . . . . . . . . . 2545SYSIBM.XSRPROPERTY table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2546

    EXPLAIN tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2547PLAN_TABLE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2548DSN_COLDIST_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2565DSN_DETCOST_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2572DSN_FILTER_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2582DSN_FUNCTION_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2587DSN_KEYTGTDIST_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2592DSN_PGRANGE_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2598DSN_PGROUP_TABLE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2602DSN_PREDICAT_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2608DSN_PREDICATE_SELECTIVITY table . . . . . . . . . . . . . . . . . . . . . . . . 2616DSN_PTASK_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2622DSN_QUERYINFO_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2627DSN_QUERY_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2633DSN_SORTKEY_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2637DSN_SORT_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2642DSN_STATEMENT_CACHE_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . 2646DSN_STATEMNT_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2655DSN_STAT_FEEDBACK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2660DSN_STRUCT_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2665DSN_VIEWREF_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2670

    Tables that support query acceleration. . . . . . . . . . . . . . . . . . . . . . . . . . 2674SYSACCEL.SYSACCELERATORS table . . . . . . . . . . . . . . . . . . . . . . . . 2675SYSACCEL.SYSACCELERATEDTABLES table . . . . . . . . . . . . . . . . . . . . . . 2676SYSACCEL.SYSACCELERATEDPACKAGES table . . . . . . . . . . . . . . . . . . . . . 2678

    Tables that are used for program authorization . . . . . . . . . . . . . . . . . . . . . . . 2681Table spaces and indexes for program authorization . . . . . . . . . . . . . . . . . . . . 2682SYSIBM.DSNPROGAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2683

    Using the catalog in database design . . . . . . . . . . . . . . . . . . . . . . . . . . 2683Retrieving catalog information about DB2 storage groups . . . . . . . . . . . . . . . . . . 2684Retrieving catalog information about a table. . . . . . . . . . . . . . . . . . . . . . . 2684Retrieving catalog information about partition order . . . . . . . . . . . . . . . . . . . . 2685Retrieving catalog information about aliases. . . . . . . . . . . . . . . . . . . . . . . 2685Retrieving catalog information about columns . . . . . . . . . . . . . . . . . . . . . . 2686Retrieving catalog information about indexes . . . . . . . . . . . . . . . . . . . . . . 2687Retrieving catalog information about views . . . . . . . . . . . . . . . . . . . . . . . 2687Retrieving catalog information about authorizations . . . . . . . . . . . . . . . . . . . . 2688Retrieving catalog information about primary keys . . . . . . . . . . . . . . . . . . . . 2688Retrieving catalog information about foreign keys . . . . . . . . . . . . . . . . . . . . . 2689Retrieving catalog information about check pending . . . . . . . . . . . . . . . . . . . . 2690Retrieving catalog information about check constraints . . . . . . . . . . . . . . . . . . . 2690Retrieving catalog information about LOBs . . . . . . . . . . . . . . . . . . . . . . . 2691Retrieving catalog information about user-defined functions and stored procedures . . . . . . . . . 2692Retrieving catalog information about triggers . . . . . . . . . . . . . . . . . . . . . . 2692

    Contents xvii

    ||

    ||

    ||

    ||||||||

  • Retrieving catalog information about sequences . . . . . . . . . . . . . . . . . . . . . 2693Adding and retrieving comments . . . . . . . . . . . . . . . . . . . . . . . . . . 2693Verifying the accuracy of the database definition . . . . . . . . . . . . . . . . . . . . . 2694

    Sample user-defined functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2694ALTDATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2696ALTTIME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2699BASE64ENCODE and BASE64DECODE . . . . . . . . . . . . . . . . . . . . . . . . 2701CURRENCY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2702DAYNAME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2704HTTPBLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2705HTTPCLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2707HTTPDELETEBLOB and HTTPDELETECLOB . . . . . . . . . . . . . . . . . . . . . . 2709HTTPGETBLOB and HTTPGETCLOB . . . . . . . . . . . . . . . . . . . . . . . . . 2710HTTPGETBLOBFILE and HTTPGETCLOBFILE. . . . . . . . . . . . . . . . . . . . . . 2712HTTPHEAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2713HTTPPOSTBLOB and HTTPPOSTCLOB . . . . . . . . . . . . . . . . . . . . . . . . 2714HTTPPUTBLOB and HTTPPUTCLOB . . . . . . . . . . . . . . . . . . . . . . . . . 2716MONTHNAME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2718TABLE_LOCATION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2719TABLE_NAME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2721TABLE_SCHEMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2723URLENCODE and URLDECODE . . . . . . . . . . . . . . . . . . . . . . . . . . 2725WEATHER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2726

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

    Notices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2731Programming interface information . . . . . . . . . . . . . . . . . . . . . . . . . . 2733Trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2733Privacy policy considerations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2734

    Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2735

    Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2737

    xviii SQL Reference

    ||

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

    ||

  • About this information

    This 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 about DB2 assumes that your DB2 subsystem is running inVersion 11 new-function mode, and that your application is running with theapplication compatibility value of 'V11R1'. Generally, new SQL capability that isdescribed, including changes to existing language elements, functions, datamanipulation statements, and limits, is available only in new-function mode withapplications set to an application compatibility value of 'V11R1'.

    The behavior of data definition statements such as CREATE, ALTER, and DROP,which embed a data manipulation SQL statement that contains new capability, isdependent on the application compatibility value that is in effect for theapplication. An application compatibility value of 'V11R1' must be in effect forapplications to use new capability in embedded statements such as SELECT,INSERT, UPDATE, DELETE, MERGE, CALL, and SETassignment-statement.Otherwise, an application compatibility value of 'V10R1' can be used for datadefinition statements.

    SQL statements that run in Version 10 new-function mode can continue to run inVersion 11 in conversion mode or in new-function mode with an applicationcompatibility value of 'V10R1', with the same expected behavior as in Version 10.

    Optimization and virtual storage enhancements are available in conversion modeunless stated otherwise.

    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.

    © Copyright IBM Corp. 1982, 2015 xix

  • DB2 Utilities Suite

    Important: 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.

    In Version 11, DB2 utilities can use the DFSORT program regardless of whetheryou purchased a license for DFSORT on your system. For more information, seethe following informational APARs:v II14047v II14213v II13495

    DB2 utilities can use IBM DB2 Sort for z/OS (5655-W42) as an alternative toDFSORT for utility SORT and MERGE functions. Use of DB2 Sort for z/OSrequires the purchase of a DB2 Sort license. For more information about DB2 Sort,see DB2 Sort for z/OS.

    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.

    Tivoli® OMEGAMON® XERefers 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 11 for z/OSAccessibility features help a user who has a physical disability, such as restrictedmobility or limited vision, to use information technology products successfully.

    xx SQL Reference

    http://www.ibm.com/software/data/db2imstools/db2tools/db2-sort/http://pic.dhe.ibm.com/infocenter/dzichelp/v2r2/topic/com.ibm.db2z11.doc.ugref/src/tpc/db2z_utlpackaging.htm

  • Accessibility features

    The following list includes the major accessibility features in z/OS products,including DB2 11 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 11 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

    For information about navigating the DB2 11 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

    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.

    Send your comments by email to [email protected] and include the name ofthe 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).

    About this information xxi

    http://www.ibm.com/ablemailto:[email protected]

  • 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 dia