sql reference - s.k. consulting v9 sql reference...references to stored procedure result sets...

2089
DB2 Version 9.1 for z/OS SQL Reference SC18-9854-05

Upload: others

Post on 02-Feb-2021

17 views

Category:

Documents


0 download

TRANSCRIPT

  • DB2 Version 9.1 for z/OS

    SQL Reference

    SC18-9854-05

    ���

  • DB2 Version 9.1 for z/OS

    SQL Reference

    SC18-9854-05

    ���

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

    Sixth edition (December 2008)

    This edition applies to DB2 Version 9.1 for z/OS (DB2 V9.1 for z/OS), product number 5635-DB2, and to anysubsequent releases until otherwise indicated in new editions. Make sure you are using the correct edition for thelevel 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 International Business Machines Corporation 1982, 2008.US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contractwith IBM Corp.

  • Contents

    About this information . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviiWho should read this information . . . . . . . . . . . . . . . . . . . . . . . . . . . xviiDB2 Utilities Suite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviiTerminology and citations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviiiAccessibility features for DB2 Version 9.1 for z/OS . . . . . . . . . . . . . . . . . . . . . xviiiHow to send your comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xixHow to read syntax diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxConventions for describing mixed data values . . . . . . . . . . . . . . . . . . . . . . . xxiiIndustry standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii

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

    Static SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Dynamic SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Deferred embedded SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Interactive SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2SQL Call Level Interface (CLI) and Open Database Connectivity (ODBC) . . . . . . . . . . . . . . 2Java database connectivity and embedded SQL for Java . . . . . . . . . . . . . . . . . . . . 3

    Schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

    Unique keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5Primary keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5Parent keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Foreign keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

    Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Unique constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Referential constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Check constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

    Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10Storage structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10Storage groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11Catalog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11DB2 views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

    Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14Stored procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

    Application processes, concurrency, and recovery. . . . . . . . . . . . . . . . . . . . . . . 15Locking, commit, and rollback . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15Unit of work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15Unit of recovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16Rolling back work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

    Packages and application plans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18Distributed data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

    Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19Distributed unit of work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19Remote unit of work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

    Character conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25Character sets and code pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28Coded character sets and CCSIDS . . . . . . . . . . . . . . . . . . . . . . . . . . . 30Determining the encoding scheme and CCSID of a string . . . . . . . . . . . . . . . . . . . 30Expanding conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

    © Copyright IBM Corp. 1982, 2008 iii

    ||

  • Contracting conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

    Chapter 2. Language elements . . . . . . . . . . . . . . . . . . . . . . . . . 35Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35Tokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

    SQL identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37Host identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38Restrictions for distributed access . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

    Naming conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39SQL path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44Qualification of unqualified object names . . . . . . . . . . . . . . . . . . . . . . . . . 45

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

    Aliases and synonyms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47Authorization, privileges, and object ownership . . . . . . . . . . . . . . . . . . . . . . . 48Authorization IDs, roles, and authorization names . . . . . . . . . . . . . . . . . . . . . . 49

    Authorization IDs and schema names . . . . . . . . . . . . . . . . . . . . . . . . . 51Authorization IDs and statement preparation . . . . . . . . . . . . . . . . . . . . . . . 51Authorization IDs and dynamic SQL . . . . . . . . . . . . . . . . . . . . . . . . . . 52Authorization IDs and remote execution. . . . . . . . . . . . . . . . . . . . . . . . . 54

    Data types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56Nulls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57Character strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60Graphic strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70Binary strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71Large objects (LOBs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72Datetime values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74Row ID values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79XML values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80Distinct types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

    Promotion of data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82Casting between data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83Assignment and comparison. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

    Numeric assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92String assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96Datetime assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99Row ID assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99XML assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100Distinct type assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100Assignments to LOB locators . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101Numeric comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101String comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102Datetime comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104Row ID comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104XML comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104Distinct type comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104

    Rules for result data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106Numeric operands. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106Character and graphic string operands . . . . . . . . . . . . . . . . . . . . . . . . . 107Binary string operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108Datetime operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108Row ID operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109XML operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109Distinct type operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109Conversion rules for operations that combine strings . . . . . . . . . . . . . . . . . . . . 109

    Constants. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113Integer constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114Floating-point constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114Decimal constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114

    iv SQL Reference

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

    ||

    ||

    ||

    ||

    ||

  • Decimal floating-point constants . . . . . . . . . . . . . . . . . . . . . . . . . . . 114Character string constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115Binary string constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116Datetime constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116Graphic string constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

    Special registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118General rules for special registers. . . . . . . . . . . . . . . . . . . . . . . . . . . 119CURRENT APPLICATION ENCODING SCHEME . . . . . . . . . . . . . . . . . . . . . 121CURRENT CLIENT_ACCTNG . . . . . . . . . . . . . . . . . . . . . . . . . . . 122CURRENT CLIENT_APPLNAME . . . . . . . . . . . . . . . . . . . . . . . . . . 123CURRENT CLIENT_USERID . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123CURRENT CLIENT_WRKSTNNAME . . . . . . . . . . . . . . . . . . . . . . . . . 123CURRENT DATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124CURRENT DEBUG MODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124CURRENT DECFLOAT ROUNDING MODE . . . . . . . . . . . . . . . . . . . . . . . 125CURRENT DEGREE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126CURRENT LOCALE LC_CTYPE . . . . . . . . . . . . . . . . . . . . . . . . . . . 127CURRENT MAINTAINED TABLE TYPES FOR OPTIMIZATION . . . . . . . . . . . . . . . . 127CURRENT MEMBER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127CURRENT OPTIMIZATION HINT . . . . . . . . . . . . . . . . . . . . . . . . . . 128CURRENT PACKAGE PATH . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128CURRENT PACKAGESET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129CURRENT PATH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129CURRENT PRECISION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130CURRENT REFRESH AGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131CURRENT ROUTINE VERSION . . . . . . . . . . . . . . . . . . . . . . . . . . . 132CURRENT RULES. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132CURRENT SCHEMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134CURRENT SERVER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134CURRENT SQLID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135CURRENT TIME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135CURRENT TIMESTAMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136CURRENT TIMEZONE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136ENCRYPTION PASSWORD . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137SESSION_USER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137USER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137Using special registers in a user-defined function or a stored procedure . . . . . . . . . . . . . . 139

    Column names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141Qualified column names. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142Correlation names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142Column name qualifiers to avoid ambiguity . . . . . . . . . . . . . . . . . . . . . . . 143Column name qualifiers in correlated references. . . . . . . . . . . . . . . . . . . . . . 144Resolution of column name qualifiers and column names . . . . . . . . . . . . . . . . . . 146

    References to variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147References to host variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148Host variables in dynamic SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . 150References to LOB host variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 150References to LOB locator variables . . . . . . . . . . . . . . . . . . . . . . . . . . 151References to XML host variables. . . . . . . . . . . . . . . . . . . . . . . . . . . 151References to file reference variables. . . . . . . . . . . . . . . . . . . . . . . . . . 153References to stored procedure result sets . . . . . . . . . . . . . . . . . . . . . . . . 154References to result set locator variables . . . . . . . . . . . . . . . . . . . . . . . . 155References to built-in session variables . . . . . . . . . . . . . . . . . . . . . . . . . 156

    Host structures in PL/I, C, and COBOL . . . . . . . . . . . . . . . . . . . . . . . . . 159Host-variable-arrays in PL/I, C, C++, and COBOL . . . . . . . . . . . . . . . . . . . . . . 160Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161

    Types of functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161Function invocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162Function resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163Best fit consideration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

    Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168

    Contents v

    ||

    ||

    ||||

    ||

    ||||

    ||

    ||||

  • Without operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170With arithmetic operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170With the concatenation operator . . . . . . . . . . . . . . . . . . . . . . . . . . . 176Scalar-fullselect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179Datetime operands and durations . . . . . . . . . . . . . . . . . . . . . . . . . . 180Datetime arithmetic in SQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181Precedence of operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185CASE expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186CAST specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189XMLCAST specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197OLAP specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199ROW CHANGE expression. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203Sequence reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204

    Predicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209Basic predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211Quantified predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213BETWEEN predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216DISTINCT predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217EXISTS predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219IN predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221LIKE predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224NULL predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230XMLEXISTS predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231

    Search conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234Options affecting SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235

    Precompiler options for dynamic statements . . . . . . . . . . . . . . . . . . . . . . . 237DECFLOAT rounding mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238Decimal point representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238Apostrophes and quotation marks as string delimiters. . . . . . . . . . . . . . . . . . . . 240Katakana characters for EBCDIC . . . . . . . . . . . . . . . . . . . . . . . . . . . 241Mixed data in character strings . . . . . . . . . . . . . . . . . . . . . . . . . . . 241Formatting of datetime strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . 242SQL standard language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242Positioned updates of columns . . . . . . . . . . . . . . . . . . . . . . . . . . . 243

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

    Chapter 3. Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247Aggregate functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254

    AVG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256CORRELATION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257COUNT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258COUNT_BIG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259COVARIANCE or COVARIANCE_SAMP . . . . . . . . . . . . . . . . . . . . . . . . 261MAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262MIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263STDDEV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264SUM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265VARIANCE or VARIANCE_SAMP . . . . . . . . . . . . . . . . . . . . . . . . . . 266XMLAGG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268

    Scalar functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270ABS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271ACOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272ADD_MONTHS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273ASCII . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275ASCII_CHR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276ASCII_STR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277ASIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278ATAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279

    vi SQL Reference

    ||||||

    ||

    ||

    ||

    ||||

  • ATANH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280ATAN2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281BIGINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282BINARY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284BLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286CCSID_ENCODING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287CEILING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288CHAR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289CHARACTER_LENGTH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297CLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299COALESCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302COLLATION_KEY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304COMPARE_DECFLOAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307CONCAT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309CONTAINS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310COS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313COSH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314DATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315DAY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317DAYOFMONTH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318DAYOFWEEK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319DAYOFWEEK_ISO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320DAYOFYEAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321DAYS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322DBCLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323DECFLOAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327DECFLOAT_SORTKEY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329DECIMAL or DEC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330DECRYPT_BINARY, DECRYPT_BIT, DECRYPT_CHAR, and DECRYPT_DB . . . . . . . . . . . . 332DEGREES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336DIFFERENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337DIGITS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338DOUBLE_PRECISION or DOUBLE . . . . . . . . . . . . . . . . . . . . . . . . . . 339DSN_XMLVALIDATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341EBCDIC_CHR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345EBCDIC_STR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346ENCRYPT_TDES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347EXP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350EXTRACT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351FLOAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353FLOOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354GENERATE_UNIQUE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355GETHINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357GETVARIABLE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358GRAPHIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360HEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364HOUR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365IDENTITY_VAL_LOCAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366IFNULL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371INSERT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372INTEGER or INT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376JULIAN_DAY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378LAST_DAY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379LCASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380LEFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381LENGTH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385LN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386LOCATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387LOCATE_IN_STRING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390LOG10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393LOWER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394

    Contents vii

    ||||

    ||

    ||||

    ||||

    ||

    ||||||

    ||

    ||

  • LPAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397LTRIM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399MAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400MICROSECOND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401MIDNIGHT_SECONDS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402MIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403MINUTE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404MOD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405MONTH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407MONTHS_BETWEEN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408MQPUBLISH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409MQPUBLISHXML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411MQREAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413MQREADCLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415MQREADXML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417MQRECEIVE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419MQRECEIVECLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421MQRECEIVEXML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423MQSEND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425MQSENDXML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427MQSENDXMLFILE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429MQSENDXMLFILECLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431MQSUBSCRIBE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433MQUNSUBSCRIBE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435MULTIPLY_ALT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437NEXT_DAY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438NORMALIZE_DECFLOAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440NORMALIZE_STRING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441NULLIF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443OVERLAY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444POSITION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448POSSTR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451POWER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453QUANTIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454QUARTER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456RADIANS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457RAISE_ERROR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458RAND. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459REAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460REPEAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462REPLACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464RID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467RIGHT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468ROUND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470ROUND_TIMESTAMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472ROWID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475RPAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476RTRIM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 478SCORE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480SECOND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482SIGN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483SIN. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484SINH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485SMALLINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486SOUNDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488SOAPHTTPC and SOAPHTTPV . . . . . . . . . . . . . . . . . . . . . . . . . . . 489SOAPHTTPNC and SOAPHTTPNV . . . . . . . . . . . . . . . . . . . . . . . . . . 490SPACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492SQRT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493STRIP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494SUBSTR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496

    viii SQL Reference

    ||

    ||||

    ||

    ||

    ||

    ||

    ||

    ||

  • SUBSTRING. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498TAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503TANH. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504TIME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505TIMESTAMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506TIMESTAMPADD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508TIMESTAMP_FORMAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 510TIMESTAMP_ISO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512TIMESTAMPDIFF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513TOTALORDER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515TRANSLATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516TRUNCATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519TRUNC_TIMESTAMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521UCASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524UNICODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525UNICODE_STR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526UPPER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527VALUE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 530VARBINARY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531VARCHAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533VARCHAR_FORMAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539VARGRAPHIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543WEEK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547WEEK_ISO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548XMLATTRIBUTES. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549XMLCOMMENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550XMLCONCAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551XMLDOCUMENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552XMLELEMENT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553XMLFOREST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558XMLNAMESPACES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561XMLPARSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563XMLPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 565XMLQUERY. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566XMLSERIALIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 570XMLTEXT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573YEAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574

    Table functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574ADMIN_TASK_LIST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575ADMIN_TASK_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580MQREADALL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583MQREADALLCLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585MQREADALLXML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 587MQRECEIVEALL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589MQRECEIVEALLCLOB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592MQRECEIVEALLXML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595XMLTABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 598

    Chapter 4. Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603Authorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604subselect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605

    from-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606where-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617group-by-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618having-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 620select-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621order-by-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626fetch-first-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629Examples of subselects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631

    fullselect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636Character conversion in set operations and concatenations . . . . . . . . . . . . . . . . . . 640

    Contents ix

    ||

    ||

    ||

    ||||

    ||

    ||||||||

    ||||||||||

    ||||

    ||

    ||||

  • Selecting the result CCSID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 641select-statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 643

    common-table-expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 644update-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 647read-only-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 648optimize-for-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 649isolation-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 650queryno-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 652SKIP LOCKED DATA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 653Examples of select statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 654

    Chapter 5. Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 657How SQL statements are invoked . . . . . . . . . . . . . . . . . . . . . . . . . . . 662

    Embedding a statement in an application program . . . . . . . . . . . . . . . . . . . . . 663Dynamic preparation and execution . . . . . . . . . . . . . . . . . . . . . . . . . . 664Static invocation of a SELECT statement . . . . . . . . . . . . . . . . . . . . . . . . 665Dynamic invocation of a SELECT statement . . . . . . . . . . . . . . . . . . . . . . . 666Interactive invocation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 666SQL diagnostics information . . . . . . . . . . . . . . . . . . . . . . . . . . . . 666Detecting and processing error and warning conditions in host language applications . . . . . . . . . 667SQL comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669

    ALLOCATE CURSOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 670ALTER DATABASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 672ALTER FUNCTION (external) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 675ALTER FUNCTION (SQL scalar) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 693ALTER INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 699ALTER PROCEDURE (external) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715ALTER PROCEDURE (SQL - external) . . . . . . . . . . . . . . . . . . . . . . . . . . 727ALTER PROCEDURE (SQL - native). . . . . . . . . . . . . . . . . . . . . . . . . . . 733ALTER SEQUENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 756ALTER STOGROUP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 761ALTER TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764ALTER TABLESPACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 814ALTER TRUSTED CONTEXT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 828ALTER VIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 840ASSOCIATE LOCATORS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 841BEGIN DECLARE SECTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 845CALL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 847CLOSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 857COMMENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 859COMMIT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 868CONNECT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 871CREATE ALIAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 877CREATE AUXILIARY TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 880CREATE DATABASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 883CREATE FUNCTION. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 886CREATE FUNCTION (external scalar) . . . . . . . . . . . . . . . . . . . . . . . . . . 887CREATE FUNCTION (external table) . . . . . . . . . . . . . . . . . . . . . . . . . . 911CREATE FUNCTION (sourced) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 929CREATE FUNCTION (SQL scalar) . . . . . . . . . . . . . . . . . . . . . . . . . . . 943CREATE GLOBAL TEMPORARY TABLE . . . . . . . . . . . . . . . . . . . . . . . . . 953CREATE INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 959CREATE PROCEDURE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 984CREATE PROCEDURE (external). . . . . . . . . . . . . . . . . . . . . . . . . . . . 985CREATE PROCEDURE (SQL - external) . . . . . . . . . . . . . . . . . . . . . . . . . 1004CREATE PROCEDURE (SQL - native) . . . . . . . . . . . . . . . . . . . . . . . . . . 1015CREATE ROLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1034CREATE SEQUENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1035CREATE STOGROUP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1043CREATE SYNONYM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1046CREATE TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1048

    x SQL Reference

    ||

    ||||||

    ||

    ||

    ||||

  • CREATE TABLESPACE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1096CREATE TRIGGER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1119CREATE TRUSTED CONTEXT . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1134CREATE TYPE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1144CREATE VIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1151DECLARE CURSOR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1158DECLARE GLOBAL TEMPORARY TABLE . . . . . . . . . . . . . . . . . . . . . . . . 1169DECLARE STATEMENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1183DECLARE TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1184DECLARE VARIABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1187DELETE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1190DESCRIBE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1203DESCRIBE CURSOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1204DESCRIBE INPUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1206DESCRIBE OUTPUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1209DESCRIBE PROCEDURE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1216DESCRIBE TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1219DROP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1222END DECLARE SECTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1239EXCHANGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1240EXECUTE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1241EXECUTE IMMEDIATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1246EXPLAIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1249FETCH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1276FREE LOCATOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1302GET DIAGNOSTICS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1303GRANT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1318GRANT (collection privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1321GRANT (database privileges). . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1322GRANT (function or procedure privileges) . . . . . . . . . . . . . . . . . . . . . . . . 1325GRANT (package privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1330GRANT (plan privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1333GRANT (schema privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1334GRANT (sequence privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1336GRANT (system privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1337GRANT (table or view privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . 1340GRANT (type or JAR privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . 1344GRANT (use privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1346HOLD LOCATOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1348INCLUDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1350INSERT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1352LABEL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1369LOCK TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1371MERGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1373OPEN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1385PREPARE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1390REFRESH TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1407RELEASE (connection) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1409RELEASE SAVEPOINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1412RENAME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1413REVOKE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1417REVOKE (collection privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1422REVOKE (database privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1424REVOKE (function or procedure privileges) . . . . . . . . . . . . . . . . . . . . . . . . 1427REVOKE (package privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1432REVOKE (plan privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1434REVOKE (schema privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1436REVOKE (sequence privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1438REVOKE (system privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1440REVOKE (table or view privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . 1443REVOKE (type or JAR privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . 1446

    Contents xi

    ||

    ||

    ||

  • REVOKE (use privileges) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1448ROLLBACK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1450SAVEPOINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1453SELECT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1455SELECT INTO. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1456SET CONNECTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1460SET CURRENT APPLICATION ENCODING SCHEME . . . . . . . . . . . . . . . . . . . . 1462SET CURRENT DEBUG MODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1463SET CURRENT DECFLOAT ROUNDING MODE . . . . . . . . . . . . . . . . . . . . . . 1465SET CURRENT DEGREE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1467SET CURRENT LOCALE LC_CTYPE . . . . . . . . . . . . . . . . . . . . . . . . . . 1468SET CURRENT MAINTAINED TABLE TYPES FOR OPTIMIZATION . . . . . . . . . . . . . . . 1470SET CURRENT OPTIMIZATION HINT . . . . . . . . . . . . . . . . . . . . . . . . . 1472SET CURRENT PACKAGE PATH . . . . . . . . . . . . . . . . . . . . . . . . . . . 1473SET CURRENT PACKAGESET . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1477SET CURRENT PRECISION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1479SET CURRENT REFRESH AGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1480SET CURRENT ROUTINE VERSION . . . . . . . . . . . . . . . . . . . . . . . . . . 1482SET CURRENT RULES. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1484SET CURRENT SQLID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1485SET ENCRYPTION PASSWORD . . . . . . . . . . . . . . . . . . . . . . . . . . . 1487SET host-variable assignment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1489SET PATH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1492SET SCHEMA. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1495SET transition-variable assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . 1498SIGNAL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1501TRUNCATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1502UPDATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1506VALUES. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1521VALUES INTO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1522WHENEVER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1524

    Chapter 6. SQL control statements for native SQL procedures. . . . . . . . . . . 1527References to SQL parameters and SQL variables . . . . . . . . . . . . . . . . . . . . . . 1528References to SQL condition names. . . . . . . . . . . . . . . . . . . . . . . . . . . 1529References to SQL cursor names. . . . . . . . . . . . . . . . . . . . . . . . . . . . 1529References to labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1529Nested compound statements and scope of names . . . . . . . . . . . . . . . . . . . . . 1530SQL-procedure-statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1532assignment-statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1534CALL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1536CASE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1538compound-statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1540FOR statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1549GET DIAGNOSTICS statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1551GOTO statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1552IF statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1554ITERATE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1555LEAVE statement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1557LOOP statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1559REPEAT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1561RESIGNAL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1563RETURN statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1566SIGNAL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1568WHILE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1572

    Appendix. Additional information for DB2 SQL . . . . . . . . . . . . . . . . . 1573Limits in DB2 for z/OS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1574Reserved schema names and reserved words . . . . . . . . . . . . . . . . . . . . . . . 1580

    Reserved schema names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1581

    xii SQL Reference

    ||||

    ||

    ||

    ||||||||

    ||

  • Reserved words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1582Characteristics of SQL statements in DB2 for z/OS . . . . . . . . . . . . . . . . . . . . . 1587

    Actions allowed on SQL statements . . . . . . . . . . . . . . . . . . . . . . . . . 1588SQL statements allowed in external functions and stored procedures . . . . . . . . . . . . . . 1592SQL statements allowed in SQL procedures . . . . . . . . . . . . . . . . . . . . . . . 1595

    SQL control statements for external SQL procedures . . . . . . . . . . . . . . . . . . . . . 1597References to SQL parameters and SQL variables . . . . . . . . . . . . . . . . . . . . . 1598SQL-procedure-statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1599assignment-statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1600CALL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1602CASE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1604compound-statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1607GET DIAGNOSTICS statement . . . . . . . . . . . . . . . . . . . . . . . . . . . 1613GOTO statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1614IF statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1616ITERATE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1618LEAVE statement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1619LOOP statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1620REPEAT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1622RESIGNAL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1623RETURN statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1626SIGNAL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1628WHILE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1632

    SQL communication area (SQLCA) . . . . . . . . . . . . . . . . . . . . . . . . . . . 1633Description of SQLCA fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1634The included SQLCA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1638The REXX SQLCA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1640

    SQL descriptor area (SQLDA) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1642Description of SQLDA fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1644Unrecognized and unsupported SQLTYPES . . . . . . . . . . . . . . . . . . . . . . . 1655The included SQLDA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1656Identifying an SQLDA in C or C++. . . . . . . . . . . . . . . . . . . . . . . . . . 1660The REXX SQLDA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1661

    DB2 catalog tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1663Table spaces and indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1664New and changed catalog tables . . . . . . . . . . . . . . . . . . . . . . . . . . 1677SYSIBM.IPLIST table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1682SYSIBM.IPNAMES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1683SYSIBM.LOCATIONS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1686SYSIBM.LULIST table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1688SYSIBM.LUMODES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1689SYSIBM.LUNAMES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1690SYSIBM.MODESELECT table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1693SYSIBM.SYSAUXRELS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1694SYSIBM.SYSCHECKDEP table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1695SYSIBM.SYSCHECKS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1696SYSIBM.SYSCHECKS2 table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1697SYSIBM.SYSCOLAUTH table. . . . . . . . . . . . . . . . . . . . . . . . . . . . 1698SYSIBM.SYSCOLDIST table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1700SYSIBM.SYSCOLDISTSTATS table . . . . . . . . . . . . . . . . . . . . . . . . . . 1702SYSIBM.SYSCOLDIST_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . . 1704SYSIBM.SYSCOLSTATS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1706SYSIBM.SYSCOLUMNS table. . . . . . . . . . . . . . . . . . . . . . . . . . . . 1708SYSIBM.SYSCOLUMNS_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . 1717SYSIBM.SYSCONSTDEP table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1721SYSIBM.SYSCONTEXT table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1722SYSIBM.SYSCONTEXTAUTHIDS table . . . . . . . . . . . . . . . . . . . . . . . . 1724SYSIBM.SYSCOPY table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1725SYSIBM.SYSCTXTTRUSTATTRS table . . . . . . . . . . . . . . . . . . . . . . . . . 1731SYSIBM.SYSDATABASE table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1732SYSIBM.SYSDATATYPES table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1734

    Contents xiii

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

    ||||

    ||

  • SYSIBM.SYSDBAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1736SYSIBM.SYSDBRM table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1739SYSIBM.SYSDEPENDENCIES table. . . . . . . . . . . . . . . . . . . . . . . . . . 1741SYSIBM.SYSDUMMY1 table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1743SYSIBM.SYSENVIRONMENT table. . . . . . . . . . . . . . . . . . . . . . . . . . 1744SYSIBM.SYSFIELDS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1746SYSIBM.SYSFOREIGNKEYS table . . . . . . . . . . . . . . . . . . . . . . . . . . 1748SYSIBM.SYSINDEXES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1749SYSIBM.SYSINDEXES_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . . 1755SYSIBM.SYSINDEXPART table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1757SYSIBM.SYSINDEXPART_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . 1761SYSIBM.SYSINDEXSPACESTATS table . . . . . . . . . . . . . . . . . . . . . . . . 1763SYSIBM.SYSINDEXSTATS table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1768SYSIBM.SYSINDEXSTATS_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . 1770SYSIBM.SYSJARCLASS_SOURCE table . . . . . . . . . . . . . . . . . . . . . . . . 1771SYSIBM.SYSJARCONTENTS table . . . . . . . . . . . . . . . . . . . . . . . . . . 1772SYSIBM.SYSJARDATA table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1773SYSIBM.SYSJAROBJECTS table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1774SYSIBM.SYSJAVAOPTS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1775SYSIBM.SYSJAVAPATHS table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1776SYSIBM.SYSKEYCOLUSE table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1777SYSIBM.SYSKEYS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1778SYSIBM.SYSKEYTARGETS table. . . . . . . . . . . . . . . . . . . . . . . . . . . 1779SYSIBM.SYSKEYTARGETSTATS table . . . . . . . . . . . . . . . . . . . . . . . . . 1782SYSIBM.SYSKEYTARGETS_HIST table . . . . . . . . . . . . . . . . . . . . . . . . 1784SYSIBM.SYSKEYTGTDIST table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1787SYSIBM.SYSKEYTGTDISTSTATS table. . . . . . . . . . . . . . . . . . . . . . . . . 1789SYSIBM.SYSKEYTGTDIST_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . 1791SYSIBM.SYSLOBSTATS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1793SYSIBM.SYSLOBSTATS_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . . 1794SYSIBM.SYSOBJROLEDEP table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1795SYSIBM.SYSPACKAGE table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1796SYSIBM.SYSPACKAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1804SYSIBM.SYSPACKDEP table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1806SYSIBM.SYSPACKLIST table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1808SYSIBM.SYSPACKSTMT table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1809SYSIBM.SYSPARMS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1812SYSIBM.SYSPKSYSTEM table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1816SYSIBM.SYSPLAN table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1818SYSIBM.SYSPLANAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1823SYSIBM.SYSPLANDEP table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1825SYSIBM.SYSPLSYSTEM table. . . . . . . . . . . . . . . . . . . . . . . . . . . . 1826SYSIBM.SYSRELS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1827SYSIBM.SYSRESAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1829SYSIBM.SYSROLES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1831SYSIBM.SYSROUTINEAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . 1832SYSIBM.SYSROUTINES table. . . . . . . . . . . . . . . . . . . . . . . . . . . . 1834SYSIBM.SYSROUTINESTEXT table . . . . . . . . . . . . . . . . . . . . . . . . . . 1844SYSIBM.SYSROUTINES_OPTS table . . . . . . . . . . . . . . . . . . . . . . . . . 1845SYSIBM.SYSROUTINES_SRC table . . . . . . . . . . . . . . . . . . . . . . . . . . 1847SYSIBM.SYSSCHEMAAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . 1848SYSIBM.SYSSEQUENCEAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . 1849SYSIBM.SYSSEQUENCES table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1851SYSIBM.SYSSEQUENCESDEP table . . . . . . . . . . . . . . . . . . . . . . . . . 1853SYSIBM.SYSSTMT table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1854SYSIBM.SYSSTOGROUP table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1858SYSIBM.SYSSTRINGS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1860SYSIBM.SYSSYNONYMS table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1862SYSIBM.SYSTABAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1863SYSIBM.SYSTABCONST table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1866SYSIBM.SYSTABLEPART table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1867

    xiv SQL Reference

    ||

    ||

    ||

    ||

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

    ||

    ||

    ||

  • SYSIBM.SYSTABLEPART_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . 1873SYSIBM.SYSTABLES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1876SYSIBM.SYSTABLESPACE table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1882SYSIBM.SYSTABLESPACESTATS table. . . . . . . . . . . . . . . . . . . . . . . . . 1887SYSIBM.SYSTABLES_HIST table. . . . . . . . . . . . . . . . . . . . . . . . . . . 1891SYSIBM.SYSTABSTATS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1893SYSIBM.SYSTABSTATS_HIST table . . . . . . . . . . . . . . . . . . . . . . . . . . 1894SYSIBM.SYSTRIGGERS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1895SYSIBM.SYSUSERAUTH table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1897SYSIBM.SYSVIEWDEP table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1900SYSIBM.SYSVIEWS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1901SYSIBM.SYSVOLUMES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1903SYSIBM.SYSXMLRELS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1904SYSIBM.SYSXMLSTRINGS table. . . . . . . . . . . . . . . . . . . . . . . . . . . 1905SYSIBM.USERNAMES table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1906SYSIBM.XSRCOMPONENT table . . . . . . . . . . . . . . . . . . . . . . . . . . 1907SYSIBM.XSROBJECTS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1908SYSIBM.XSROBJECTCOMPONENTS table . . . . . . . . . . . . . . . . . . . . . . . 1910SYSIBM.XSROBJECTGRAMMAR table . . . . . . . . . . . . . . . . . . . . . . . . 1911SYSIBM.XSROBJECTHIERARCHIES table . . . . . . . . . . . . . . . . . . . . . . . 1912SYSIBM.XSROBJECTPROPERTY table . . . . . . . . . . . . . . . . . . . . . . . . . 1913SYSIBM.XSRPROPERTY table . . . . . . . . . . . . . . . . . . . . . . . . . . . 1914

    Using the catalog in database design . . . . . . . . . . . . . . . . . . . . . . . . . . 1914Retrieving catalog information about DB2 storage groups . . . . . . . . . . . . . . . . . . 1914Retrieving catalog information about a table. . . . . . . . . . . . . . . . . . . . . . . 1915Retrieving catalog information about partition order . . . . . . . . . . . . . . . . . . . . 1915Retrieving catalog information about aliases. . . . . . . . . . . . . . . . . . . . . . . 1915Retrieving catalog information about columns . . . . . . . . . . . . . . . . . . . . . . 1916Retrieving catalog information about indexes . . . . . . . . . . . . . . . . . . . . . . 1917Retrieving catalog information about views . . . . . . . . . . . . . . . . . . . . . . . 1917Retrieving catalog information about authorizations . . . . . . . . . . . . . . . . . . . . 1918Retrieving catalog information about primary keys . . . . . . . . . . . . . . . . . . . . 1918Retrieving catalog information about foreign keys . . . . . . . . . . . . . . . . . . . . . 1919Retrieving catalog information about check pending . . . . . . . . . . . . . . . . . . . . 1919Retrieving catalog information about check constraints . . . . . . . . . . . . . . . . . . . 1920Retrieving catalog information about LOBs . . . . . . . . . . . . . . . . . . . . . . . 1920Retrieving catalog information about user-defined functions and stored procedures . . . . . . . . . 1921Retrieving catalog information about triggers . . . . . . . . . . . . . . . . . . . . . . 1921Retrieving catalog information about sequences . . . . . . . . . . . . . . . . . . . . . 1922Adding and retrieving comments . . . . . . . . . . . . . . . . . . . . . . . . . . 1922Verifying the accuracy of the database definition . . . . . . . . . . . . . . . . . . . . . 1923

    Sample user-defined functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1923ALTDATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1925ALTTIME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1928CURRENCY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1930DAYNAME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1932MONTHNAME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1933TABLE_LOCATION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1934TABLE_NAME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1936TABLE_SCHEMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1938WEATHER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1940

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

    How to obtain DB2 information . . . . . . . . . . . . . . . . . . . . . . . . 1949

    How to use the DB2 library . . . . . . . . . . . . . . . . . . . . . . . . . . 1953

    Notices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1957Programming Interface Information . . . . . . . . . . . . . . . . . . . . . . . . . . 1959

    Contents xv

    ||

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

  • General-use Programming Interface and Associated Guidance Information . . . . . . . . . . . . 1960Product-sensitive Programming Interface and Associated Guidance Information. . . . . . . . . . . 1961

    Trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1961

    Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1963

    Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2007

    xvi 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.

    This information assumes that your DB2 subsystem is running in Version 9.1new-function mode. Generally, new functions that are described, including changesto existing functions, statements, and limits, are available only in new-functionmode. Two exceptions to this general statement are new and changed utilities andoptimization enhancements, which are also available in conversion mode unlessstated otherwise.

    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.

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

    The DB2 Utilities Suite is designed to work with the DFSORT™ program, whichyou are licensed to use in support of the DB2 utilities even if you do not otherwiselicense DFSORT for general use. If your primary sort product is not DFSORT,consider the following informational APARs mandatory reading:v II14047/II14213: USE OF DFSORT BY DB2 UTILITIESv II13495: HOW DFSORT TAKES ADVANTAGE OF 64-BIT REAL

    ARCHITECTURE

    These informational APARs are periodically updated.

    © Copyright IBM Corp. 1982, 2008 xvii

  • Related information

    DB2 utilities packaging (Utility Guide)

    Terminology and citationsIn this information, DB2 Version 9.1 for z/OS is referred to as ″DB2 for z/OS.″ Incases where the context makes the meaning clear, DB2 for z/OS is referred to as″DB2.″ When this information refers to titles of DB2 for z/OS books, a short title isused. (For example, ″See DB2 SQL Reference″ is a citation to IBM DB2 Version 9.1 forz/OS SQL Reference.)

    When 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 Version 9.1 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 Version 9.1 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 Version 9.1 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.

    xviii SQL Reference

    |

    http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/topic/com.ibm.db29.doc.ugref/db2z_utlpackaging.htm

  • Keyboard navigation

    You can access DB2 Version 9.1 for z/OS ISPF panel functions by using a keyboardor keyboard shortcut keys.

    For information about navigating the DB2 Version 9.1 for z/OS ISPF panels usingTSO/E or ISPF, refer to the z/OS TSO/E Primer, the z/OS TSO/E User’s Guide, andthe z/OS ISPF User’s Guide. These guides describe how to navigate each interface,including the use of keyboard shortcuts or function keys (PF keys). Each guideincludes the default settings for the PF keys and explains how to modify theirfunctions.

    Related accessibility information

    Online documentation for DB2 Version 9.1 for z/OS is available in the InformationManagement Software for z/OS Solutions Information Center, which is available atthe following Web site: http://publib.boulder.ibm.com/infocenter/dzichelp

    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 e-mail to [email protected] and include the name

    of the product, the version number of the product, and the number of the book.If you are commenting on specific text, please list the location of the text (forexample, a chapter and section title or a help topic title).

    v You can send comments from the Web. Visit the DB2 for z/OS - TechnicalResources Web site at:

    http://www.ibm.com/support/docview.wss?&uid=swg27011656

    This Web site has an online reader comment form that you can use to sendcomments.

    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://publib.boulder.ibm.com/infocenter/db2zhelp.

    About this information xix

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

    xx 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 xxi

    |||

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

    |

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

    |

    |||

  • 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

    xxii SQL Reference

  • Industry standards

    DB2 for z/OS is developed based on the following industry standards for SQL:v Information technology - Database languages - SQL- Part 1: Framework

    (SQL/Framework) ISO/IEC 9075-1:2003

    v Information technology - Database languages - SQL- Part 2: Foundation(SQL/Foundation) ISO/IEC 9075-2:2003

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

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

    v Information technology - Database languages - SQL- Part 10: Object LanguageBindings (SQL/OLB) ISO/IEC 9075-10:2003

    v Information technology - Database languages - SQL- Part 13: SQL Routines and TypesUsing the Java™ Programming Language (SQL/JRT) ISO/IEC 9075-13:2002

    v Information technology - Database languages - SQL- Part 14: XML-RelatedSpecifications (SQL/XML) ISO/IEC 9075-14:2006

    v ANSI (American National Standards Institute) X3.135-1999, Database LanguageSQL

    About this information xxiii

    ||

    ||

    ||

    ||

    ||

    ||

    ||

    ||

  • xxiv SQL Reference

  • Chapter 1. DB2 concepts

    Certain DB2 concepts are important to understand when using Structured QueryLanguage (SQL).

    The following topics provide information on these concepts:v “Structured query language”v “Schemas” on page 3v “Tables” on page 3v “Indexes” on page 5v “Keys” on page 5v “Constraints” on page 6v “Triggers” on page 10v “Storage structures” on page 10v “Storage groups” on page 11v “Databases” on page 11v “Catalog” on page 11v “DB2 views” on page 11v “Sequences” on page 13v “Routines” on page 14v “Application processes, concurrency, and recovery” on page 15v “Packages and application plans” on page 18v “Distributed data” on page 18v “Character conversion” on page 25

    Structured query languageStructured query language (SQL) is a standardized language for defining andmanipulating data in a relational database.

    In accordance with the relational model of data, the database is perceived as a setof tables, relationships are represented by values in tables, and data is retrieved byspecifying a result table that can be derived from one or more tables. DB2 for z/OStransforms the specification of a result table into a sequence of internal operationsthat optimize data retrieval. This transformation occurs when the SQL statement isprepared. This transformation is also known as binding.

    All executable SQL statements must be prepared before they can be executed. Theresult of preparation is the executable or operational form of the statement. Themethod of preparing an SQL statement and the persistence of its operational formdistinguish static SQL from dynamic SQL.

    Static SQLThe source form of a static SQL statement is embedded within an applicationprogram written in a host language such as COBOL. The statement is preparedbefore the program is executed and the operational form of the statement persistsbeyond the execution of the program.

    © Copyright IBM Corp. 1982, 2008 1

  • Static SQL statements in a source program must be processed before the programis compiled. This processing can be accomplished through the DB2 precompiler orthe DB2 coprocessor. The DB2 precompiler or the coprocessor checks the syntax ofthe SQL statements, turns them into host language comments, and generates hostlanguage statements to invoke DB2.

    The preparation of an SQL application program includes precompilation, thepreparation of its static SQL statements, and compilation of the modified sourceprogram, as described in DB2 Application Programming and SQL Guide.

    Dynamic SQLPrograms that contain embedded dynamic SQL statements must be precompiledlike those that contain static SQL, but unlike static SQL, the dynamic statementsare constructed and prepared at run time.

    The source form of a dynamic statement is a character string that is passed to DB2by the program using the static SQL PREPARE or EXECUTE IMMEDIATEstatement. A statement that is prepared using the PREPARE statement can bereferenced in a DECLARE CURSOR, DESCRIBE, or EXECUTE statement. Whetherthe operational form of the statement is persistent depends on whether dynamicstatement caching is enabled. For details on dynamic statement caching, see DB2Application Programming and SQL Guide.

    SQL statements embedded in a REXX™ application are dynamic SQL statements.SQL statements submitted to an interactive SQL facility and to the CALL LevelInterface (CLI) are also dynamic SQL.

    Deferred embedded SQLA deferred embedded SQL statement is neither fully static nor fully dynamic.

    Like a static statement, it is embedded within an application, but like a dynamicstatement, it is prepared during the execution of the application. Althoughprepared at run time, a deferred embedded SQL statement is processed withbind-time rules such that the authorization ID and qualifier determined at bindtime for the plan or package owner are used. Deferred embedded SQL statementsare used for DB2 private protocol access to remote data.

    Interactive SQLInteractive SQL refers to SQL statements submitted using SPUFI (SQL processorusing file input) or the command line processor.

    SPUFI and the command line processor prepares and executes these statementsdynamically. For more details about using SPUFI, see DB2 Application Programmingand SQL Guide. For more details about using the command line processor, see DB2Command Reference.

    SQL Call Level Interface (CLI) and Open DatabaseConnectivity (ODBC)

    The DB2 Call Level Interface (CLI) is an application programming interface inwhich functions are provided to application programs to process dynamic SQLstatements.

    DB2 CLI allows users to access SQL functions directly through a call interface. CLIprograms can also be compiled using an Open Database Connectivity (ODBC)

    2 SQL Reference

    ||||

  • Software Developer’s Kit, available from Microsoft® or other vendors, enablingaccess to ODBC data sources. Unlike using embedded SQL, no precompilation isrequired. Applications developed using this interface can be executed on a varietyof databases without being compiled against each of databases. Through theinterface, applications use procedure calls at execution time to connect todatabases, to issue SQL statements, and to get returned data and statusinformation.

    The DB2 ODBC Guide and Reference describes the APIs supported with thisinterface.

    Java database connectivity and embedded SQL for JavaDB2 provides two standards-based Java programming APIs: Java DatabaseConnectivity (JDBC) and embedded SQL for Java (SQL/OLB or SQLJ). Both can beused to create Java applications and applets that access DB2.

    Static SQL cannot be used by JDBC. SQLJ applications use JDBC as a foundationfor such tasks as connecting to databases and handling SQL errors, but can containembedded static SQL statements in the SQLJ source files. An SQLJ file has to betranslated with the SQLJ translator before the resulting Java source code can becompiled.

    The DB2 Application Programming Guide and Reference for Java describes the APIssupported with these interfaces.

    SchemasThe objects in a relational database are organized into sets called schemas. Aschema provides a logical classification of objects in the database. The schema nameis used as the qualifier of SQL object names such as tables, views, indexes, andtriggers.

    The schema name of the object determines the schema to which the object belongs.A user object, such as a distinct type, function, procedure, sequence, or triggershould not be created in a system schema, which is any one of a set of schemas thatare reserved for use by the DB2 subsystem.

    All schemas that are listed “Reserved schema names” on page 1581 are systemschemas.

    TablesTables are logical structures maintained by DB2. Tables are made up of columns androws. There is no inherent order of the rows within a table. At the intersection ofevery column and row is a specific data item called a value.

    A column is a set of values of the same type. A row is a sequence of values suchthat the nth value is a value of the nth column of the table. Every table must haveone or more columns, but the number of rows can be zero.

    Some types of tables include:

    auxiliary tableA table created with the SQL statement CREATE AUXILIARY TABLE andused to hold the data for a column that is defined in a base table.

    Chapter 1. DB2 concepts 3

    |

    ||||

    ||||

    ||

  • base tableA table created with the SQL statement CREATE TABLE and used to holdpersistent user data.

    clone tableA table that is structurally identical to a base table. A clone table is createdfrom a base table by using the ALTER TABLE statement that includes anADD CLONE clause that specifies the name of the clone table. The basetable and clone table each have separate underlying VSAM data sets(identified by their data set instance numbers) that contain separate rowsof data.

    empty tableA table with zero rows.

    materialized query tableA table created with the SQL statement CREATE TABLE and used tocontain materialized data that is derived from one or more source tablesspecified by a fullselect. A source table is a base table, view, tableexpression, or user-defined table function. The fullselect specifies thequeries that are used to refresh the materialized query table and to keepthe data in the materialized query table synchronized with the data in thesource tables from which the materialized query table was derived. Thefullselect is used to determine the column definitions of a materializedquery table and is executed against the source tables to populate thematerialized query table.

    A materialized query table can be either user-maintained orsystem-maintained. A user-maintained materialized query table can beupdated by the user with a data change statement, the REFRESH TABLEstatement, and with the LOAD utility. A system-maintained materializedquery table can be updated only through the REFRESH TABLE statement.

    Materialized query tables can be used to improve the performance ofdynamic SQL queries. If the database manager determines that a portion ofa query could be resolved using a materialized query table, the querymight be rewritten by the database manager to use the materialized querytable. This de