Top Banner
iSeries DB2 Universal Database for iSeries SQL Reference Version 5 E Rserver
682

DB2 UDB for iSeries SQL Reference V5R1 - · PDF fileDB2 Universal Database for iSeries SQL Reference Version 5 ERserver. ... and Embedded SQL for Java (SQLJ) Programs ... xxii DB2

Feb 05, 2018

Download

Documents

hoanghuong
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • iSeries

    DB2 Universal Database for iSeries SQL ReferenceVersion 5

    ERserver

  • iSeries

    DB2 Universal Database for iSeries SQL ReferenceVersion 5

    ERserver

  • Copyright International Business Machines Corporation 1998, 2001. All rights reserved.US Government Users Restricted Rights Use, duplication or disclosure restricted by GSA ADP Schedule Contractwith IBM Corp.

  • Contents

    About DB2 UDB for iSeries SQL Reference. . . . . . . . . . . . . . . . . . . . . . xxiStandards Compliance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiWho should read the SQL Reference book . . . . . . . . . . . . . . . . . . . . . . . xxi

    Assumptions Relating to Examples of SQL Statements . . . . . . . . . . . . . . . . . xxiiHow to Read Syntax Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . xxii

    Conventions for Describing Mixed Data Values . . . . . . . . . . . . . . . . . . . . . xxiiiWhats new for V5R1 in the SQL Reference book . . . . . . . . . . . . . . . . . . . . xxiv

    Chapter 1. Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Relational Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Structured Query Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

    Static SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Dynamic SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Extended Dynamic SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Interactive SQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2SQL Call Level Interface (CLI) and Open Database Connectivity (ODBC) . . . . . . . . . . . 3Java Database Connectivity (JDBC) and Embedded SQL for Java (SQLJ) Programs . . . . . . . 3

    Schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Primary Keys and Unique Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Referential Integrity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5Check Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10Packages and Access Plans . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10Catalog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12Application Processes, Concurrency, and Recovery . . . . . . . . . . . . . . . . . . . . 12Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16Isolation Level. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18Distributed Relational Database . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

    Database Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21CONNECT (Type 1) and CONNECT (Type 2) . . . . . . . . . . . . . . . . . . . . . 22Remote Unit of Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Application-Directed Distributed Unit of Work . . . . . . . . . . . . . . . . . . . . . 24Data Representation Considerations . . . . . . . . . . . . . . . . . . . . . . . . 26

    Character Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27Character Sets and Code Pages . . . . . . . . . . . . . . . . . . . . . . . . . . 28Coded Character Sets and CCSIDs. . . . . . . . . . . . . . . . . . . . . . . . . 29Default CCSID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

    Sort Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Authorization and Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30Storage Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

    Chapter 2. Language Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . 33Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34Tokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

    SQL Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36System identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

    Copyright IBM Corp. 1998, 2001 iii

    ||

  • Host Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37Naming Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

    Qualification of Unqualified Object Names . . . . . . . . . . . . . . . . . . . . . . 42SQL Names and System Names: Special Considerations . . . . . . . . . . . . . . . . . 44

    Schemas and the SQL Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44Authorization IDs and Authorization-Names . . . . . . . . . . . . . . . . . . . . . . . 45

    Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

    Binary Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49Character Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49Character Subtypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50Graphic Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50Graphic Subtypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51Large Objects (LOBs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51Numbers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53Datetime Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53DataLink Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56User-Defined Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

    Promotion of Data Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58Casting Between Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59Assignments and Comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

    Numeric Assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63String Assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64Datetime Assignments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66DataLink Assignments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67Distinct Type Assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68Numeric Comparisons. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69String Comparisons. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69Datetime Comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71Distinct Type Comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71

    Rules for Result Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72Binary String Operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72Character and Graphic String Operands . . . . . . . . . . . . . . . . . . . . . . . 73Numeric Operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73Datetime Operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74DATALINK Operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74DISTINCT Type Operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

    Conversion Rules for Operations That Combine Strings . . . . . . . . . . . . . . . . . . 75Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

    Integer Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76Floating-Point Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76Decimal Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77Binary-String Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77Character-String Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77Graphic-String Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78Decimal Point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79Delimiters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

    Special Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80CURRENT DATE or CURRENT_DATE . . . . . . . . . . . . . . . . . . . . . . . 80CURRENT PATH, CURRENT_PATH, or CURRENT FUNCTION PATH . . . . . . . . . . . . 80CURRENT SERVER or CURRENT_SERVER . . . . . . . . . . . . . . . . . . . . . 81CURRENT TIME or CURRENT_TIME . . . . . . . . . . . . . . . . . . . . . . . . 81CURRENT TIMESTAMP or CURRENT_TIMESTAMP . . . . . . . . . . . . . . . . . . 81CURRENT TIMEZONE or CURRENT_TIMEZONE . . . . . . . . . . . . . . . . . . . 82USER. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

    iv DB2 UDB for iSeries SQL Reference V5R1

  • Column Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82Qualified Column Names. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82Correlation Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83Column Name Qualifiers to Avoid Ambiguity. . . . . . . . . . . . . . . . . . . . . . 84Column Name Qualifiers in Correlate