sql reference, volume 1 - fachhochschule stralsunddblabor.fh-stralsund.de/skripte/sql reference vol...

833
IBM ® DB2 Universal Database SQL Reference Volume 1 Version 8.2 SC09-4844-01

Upload: ngoque

Post on 26-Jul-2018

250 views

Category:

Documents


0 download

TRANSCRIPT

  • IBM

    DB2

    Universal

    Database

    SQL

    Reference

    Volume

    1

    Version

    8.2

    SC09-4844-01

  • IBM

    DB2

    Universal

    Database

    SQL

    Reference

    Volume

    1

    Version

    8.2

    SC09-4844-01

  • Before

    using

    this

    information

    and

    the

    product

    it

    supports,

    be

    sure

    to

    read

    the

    general

    information

    under

    Notices.

    This

    document

    contains

    proprietary

    information

    of

    IBM.

    It

    is

    provided

    under

    a

    license

    agreement

    and

    is

    protected

    by

    copyright

    law.

    The

    information

    contained

    in

    this

    publication

    does

    not

    include

    any

    product

    warranties,

    and

    any

    statements

    provided

    in

    this

    manual

    should

    not

    be

    interpreted

    as

    such.

    You

    can

    order

    IBM

    publications

    online

    or

    through

    your

    local

    IBM

    representative.

    v

    To

    order

    publications

    online,

    go

    to

    the

    IBM

    Publications

    Center

    at

    www.ibm.com/shop/publications/order

    v

    To

    find

    your

    local

    IBM

    representative,

    go

    to

    the

    IBM

    Directory

    of

    Worldwide

    Contacts

    at

    www.ibm.com/planetwide

    To

    order

    DB2

    publications

    from

    DB2

    Marketing

    and

    Sales

    in

    the

    United

    States

    or

    Canada,

    call

    1-800-IBM-4YOU

    (426-4968).

    When

    you

    send

    information

    to

    IBM,

    you

    grant

    IBM

    a

    nonexclusive

    right

    to

    use

    or

    distribute

    the

    information

    in

    any

    way

    it

    believes

    appropriate

    without

    incurring

    any

    obligation

    to

    you.

    Copyright

    International

    Business

    Machines

    Corporation

    1993

    -

    2004.

    All

    rights

    reserved.

    US

    Government

    Users

    Restricted

    Rights

    Use,

    duplication

    or

    disclosure

    restricted

    by

    GSA

    ADP

    Schedule

    Contract

    with

    IBM

    Corp.

    http://www.ibm.com/shop/publications/orderhttp://www.ibm.com/planetwide
  • Contents

    About

    this

    book

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . ix

    Who

    should

    use

    this

    book

    .

    .

    .

    .

    .

    .

    .

    .

    . ix

    How

    this

    book

    is

    structured

    .

    .

    .

    .

    .

    .

    .

    .

    . ix

    A

    brief

    overview

    of

    Volume

    2

    .

    .

    .

    .

    .

    .

    .

    . x

    How

    to

    read

    the

    syntax

    diagrams

    .

    .

    .

    .

    .

    .

    . x

    Common

    syntax

    elements

    .

    .

    .

    .

    .

    .

    .

    .

    . xii

    Function

    designator

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . xii

    Method

    designator

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . xiii

    Procedure

    designator

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . xv

    Conventions

    used

    in

    this

    manual

    .

    .

    .

    .

    .

    .

    . xvi

    Error

    conditions

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . xvi

    Highlighting

    conventions

    .

    .

    .

    .

    .

    .

    .

    . xvi

    Related

    documentation

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . xvii

    Chapter

    1.

    Concepts

    .

    .

    .

    .

    .

    .

    .

    .

    . 1

    Relational

    databases

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 1

    Structured

    Query

    Language

    (SQL)

    .

    .

    .

    .

    .

    .

    . 1

    Privileges,

    authority

    levels,

    and

    database

    authorities

    1

    Schemas

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 5

    Tables

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 6

    Views

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 7

    Aliases

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 7

    Indexes

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 8

    Keys

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 8

    Constraints

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 8

    Unique

    constraints

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 9

    Referential

    constraints

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 9

    Table

    check

    constraints

    .

    .

    .

    .

    .

    .

    .

    .

    . 12

    Informational

    constraints

    .

    .

    .

    .

    .

    .

    .

    .

    . 13

    Isolation

    levels

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 13

    Comparison

    of

    isolation

    levels

    .

    .

    .

    .

    .

    .

    . 15

    Queries

    and

    table

    expressions

    .

    .

    .

    .

    .

    .

    .

    . 16

    Application

    processes,

    concurrency,

    and

    recovery

    .

    . 16

    DB2

    Call

    level

    interface

    (CLI)

    and

    open

    database

    connectivity

    (ODBC)

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 18

    Java

    database

    connectivity

    (JDBC)

    and

    embedded

    SQL

    for

    Java

    (SQLJ)

    programs

    .

    .

    .

    .

    .

    .

    .

    . 19

    Packages

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 19

    Catalog

    views

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 19

    Character

    conversion

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 20

    Event

    monitors

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 22

    Triggers

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 23

    Table

    spaces

    and

    other

    storage

    structures

    .

    .

    .

    . 24

    Data

    partitioning

    across

    multiple

    partitions

    .

    .

    .

    . 26

    Distributed

    relational

    databases

    .

    .

    .

    .

    .

    .

    .

    . 27

    Remote

    unit

    of

    work

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 28

    Application-directed

    distributed

    unit

    of

    work

    .

    . 31

    Data

    representation

    considerations

    .

    .

    .

    .

    .

    . 35

    DB2

    federated

    systems

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 35

    Federated

    systems

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 35

    The

    federated

    server

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 36

    What

    is

    a

    data

    source?

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 37

    Supported

    data

    sources

    .

    .

    .

    .

    .

    .

    .

    .

    . 37

    The

    federated

    database

    .

    .

    .

    .

    .

    .

    .

    .

    . 39

    The

    federated

    database

    system

    catalog

    .

    .

    .

    . 40

    The

    SQL

    Compiler

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 41

    The

    query

    optimizer

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 41

    Compensation

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 42

    Pass-through

    sessions

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 43

    Wrappers

    and

    wrapper

    modules

    .

    .

    .

    .

    .

    . 44

    Default

    wrapper

    names

    .

    .

    .

    .

    .

    .

    .

    .

    . 45

    Server

    definitions

    and

    server

    options

    .

    .

    .

    .

    . 46

    User

    mappings

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 46

    Nicknames

    and

    data

    source

    objects

    .

    .

    .

    .

    . 47

    Valid

    data

    source

    objects

    .

    .

    .

    .

    .

    .

    .

    .

    . 47

    Nickname

    column

    options

    .

    .

    .

    .

    .

    .

    .

    . 48

    Data

    type

    mappings

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 49

    Function

    mappings

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 50

    Index

    specifications

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 50

    Collating

    sequences

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 51

    Chapter

    2.

    Language

    elements

    .

    .

    .

    . 55

    Characters

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 55

    Tokens

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 57

    Identifiers

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 58

    Naming

    conventions

    and

    implicit

    object

    name

    qualifications

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 58

    Aliases

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 62

    Authorization

    IDs

    and

    authorization

    names

    .

    . 63

    Column

    names

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 66

    References

    to

    host

    variables

    .

    .

    .

    .

    .

    .

    .

    . 72

    Data

    types

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 79

    Data

    types

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 79

    Numbers

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 80

    Character

    strings

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 81

    Graphic

    strings

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 82

    Binary

    strings

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 83

    Large

    objects

    (LOBs)

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 84

    Datetime

    values

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 85

    DATALINK

    values

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 88

    XML

    values

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 90

    User-defined

    types

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 91

    Promotion

    of

    data

    types

    .

    .

    .

    .

    .

    .

    .

    .

    . 94

    Casting

    between

    data

    types

    .

    .

    .

    .

    .

    .

    .

    . 96

    Assignments

    and

    comparisons

    .

    .

    .

    .

    .

    .

    . 99

    Rules

    for

    result

    data

    types

    .

    .

    .

    .

    .

    .

    .

    . 113

    Rules

    for

    string

    conversions

    .

    .

    .

    .

    .

    .

    . 117

    Partition-compatible

    data

    types

    .

    .

    .

    .

    .

    . 119

    Constants

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 121

    Integer

    constants

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 121

    Floating-point

    constants

    .

    .

    .

    .

    .

    .

    .

    .

    . 121

    Decimal

    constants

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 122

    Character

    string

    constants

    .

    .

    .

    .

    .

    .

    .

    . 122

    Hexadecimal

    constants

    .

    .

    .

    .

    .

    .

    .

    .

    . 122

    Graphic

    string

    constants

    .

    .

    .

    .

    .

    .

    .

    .

    . 123

    Special

    registers

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 124

    Special

    registers

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 124

    CURRENT

    CLIENT_ACCTNG

    .

    .

    .

    .

    .

    . 126

    CURRENT

    CLIENT_APPLNAME

    .

    .

    .

    .

    . 127

    CURRENT

    CLIENT_USERID

    .

    .

    .

    .

    .

    .

    . 128

    Copyright

    IBM

    Corp.

    1993

    -

    2004

    iii

    ||

    |

    |

    |

    |

  • CURRENT

    CLIENT_WRKSTNNAME

    .

    .

    .

    . 129

    CURRENT

    DATE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 130

    CURRENT

    DBPARTITIONNUM

    .

    .

    .

    .

    .

    . 131

    CURRENT

    DEFAULT

    TRANSFORM

    GROUP

    132

    CURRENT

    DEGREE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 133

    CURRENT

    EXPLAIN

    MODE

    .

    .

    .

    .

    .

    .

    . 134

    CURRENT

    EXPLAIN

    SNAPSHOT

    .

    .

    .

    .

    . 135

    CURRENT

    ISOLATION

    .

    .

    .

    .

    .

    .

    .

    .

    . 136

    CURRENT

    LOCK

    TIMEOUT

    .

    .

    .

    .

    .

    .

    . 137

    CURRENT

    MAINTAINED

    TABLE

    TYPES

    FOR

    OPTIMIZATION

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 138

    CURRENT

    PACKAGE

    PATH

    .

    .

    .

    .

    .

    .

    . 139

    CURRENT

    PATH

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 140

    CURRENT

    QUERY

    OPTIMIZATION

    .

    .

    .

    . 141

    CURRENT

    REFRESH

    AGE

    .

    .

    .

    .

    .

    .

    .

    . 142

    CURRENT

    SCHEMA

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 143

    CURRENT

    SERVER

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 144

    CURRENT

    TIME

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 145

    CURRENT

    TIMESTAMP

    .

    .

    .

    .

    .

    .

    .

    . 146

    CURRENT

    TIMEZONE

    .

    .

    .

    .

    .

    .

    .

    .

    . 147

    CURRENT

    USER

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 148

    SESSION_USER

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 149

    SYSTEM_USER

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 150

    USER

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 151

    Functions

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 152

    External,

    SQL,

    and

    sourced

    user-defined

    functions

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 152

    Scalar,

    column,

    row,

    and

    table

    user-defined

    functions

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 152

    Function

    signatures

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 153

    Function

    resolution

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 153

    Function

    invocation

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 157

    Conservative

    binding

    semantics

    .

    .

    .

    .

    .

    . 157

    Methods

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 160

    External

    and

    SQL

    user-defined

    methods

    .

    .

    . 160

    Method

    signatures

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 160

    Method

    resolution

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 161

    Method

    invocation

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 164

    Dynamic

    dispatch

    of

    methods

    .

    .

    .

    .

    .

    .

    . 165

    Expressions

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 168

    Expressions

    without

    operators

    .

    .

    .

    .

    .

    .

    . 169

    Expressions

    with

    the

    concatenation

    operator

    .

    . 169

    Expressions

    with

    arithmetic

    operators

    .

    .

    .

    . 171

    Two-integer

    operands

    .

    .

    .

    .

    .

    .

    .

    .

    . 172

    Integer

    and

    decimal

    operands

    .

    .

    .

    .

    .

    .

    . 173

    Two-decimal

    operands

    .

    .

    .

    .

    .

    .

    .

    .

    . 173

    Decimal

    arithmetic

    in

    SQL

    .

    .

    .

    .

    .

    .

    .

    . 173

    Floating-point

    operands

    .

    .

    .

    .

    .

    .

    .

    .

    . 173

    User-defined

    types

    as

    operands

    .

    .

    .

    .

    .

    . 174

    Scalar

    fullselect

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 174

    Datetime

    operations

    and

    durations

    .

    .

    .

    .

    . 174

    Datetime

    arithmetic

    in

    SQL

    .

    .

    .

    .

    .

    .

    .

    . 175

    Precedence

    of

    operations

    .

    .

    .

    .

    .

    .

    .

    . 179

    CASE

    expressions

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 179

    CAST

    specifications

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 181

    Dereference

    operations

    .

    .

    .

    .

    .

    .

    .

    .

    . 183

    OLAP

    functions

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 184

    XML

    functions

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 189

    Method

    invocation

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 198

    Subtype

    treatment

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 199

    Sequence

    reference

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 199

    Predicates

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 204

    Predicates

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 204

    Search

    conditions

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 205

    Basic

    predicate

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 208

    Quantified

    predicate

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 209

    BETWEEN

    predicate

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 212

    EXISTS

    predicate

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 213

    IN

    predicate

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 214

    LIKE

    predicate

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 216

    NULL

    predicate

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 221

    TYPE

    predicate

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 222

    Chapter

    3.

    Functions

    .

    .

    .

    .

    .

    .

    .

    . 225

    Functions

    overview

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 225

    Supported

    functions

    and

    SQL

    administrative

    routines

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 227

    Aggregate

    functions

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 257

    AVG

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 258

    CORRELATION

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 260

    COUNT

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 261

    COUNT_BIG

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 262

    COVARIANCE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 264

    GROUPING

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 265

    MAX

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 267

    MIN

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 269

    Regression

    functions

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 270

    STDDEV

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 273

    SUM

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 274

    VARIANCE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 275

    Scalar

    functions

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 276

    ABS

    or

    ABSVAL

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 277

    ACOS

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 278

    ASCII

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 279

    ASIN

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 280

    ATAN

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 281

    ATAN2

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 282

    ATANH

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 283

    BIGINT

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 284

    BLOB

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 286

    CEILING

    or

    CEIL

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 287

    CHAR

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 288

    CHR

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 292

    CLOB

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 293

    COALESCE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 294

    CONCAT

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 295

    COS

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 296

    COSH

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 297

    COT

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 298

    DATE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 299

    DAY

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 300

    DAYNAME

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 301

    DAYOFWEEK

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 302

    DAYOFWEEK_ISO

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 303

    DAYOFYEAR

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 304

    DAYS

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 305

    DBCLOB

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 306

    DBPARTITIONNUM

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 307

    DECIMAL

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 309

    DECRYPT_BIN

    and

    DECRYPT_CHAR

    .

    .

    .

    .

    . 313

    DEGREES

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 315

    DEREF

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 316

    iv

    SQL

    Reference,

    Volume

    1

    ||||

    ||

    ||||||

  • DIFFERENCE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 317

    DIGITS

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 318

    DLCOMMENT

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 319

    DLLINKTYPE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 320

    DLNEWCOPY

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 321

    DLPREVIOUSCOPY

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 323

    DLREPLACECONTENT

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 325

    DLURLCOMPLETE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 327

    DLURLCOMPLETEONLY

    .

    .

    .

    .

    .

    .

    .

    .

    . 328

    DLURLCOMPLETEWRITE

    .

    .

    .

    .

    .

    .

    .

    .

    . 329

    DLURLPATH

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 330

    DLURLPATHONLY

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 331

    DLURLPATHWRITE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 332

    DLURLSCHEME

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 333

    DLURLSERVER

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 334

    DLVALUE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 335

    DOUBLE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 336

    ENCRYPT

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 338

    EVENT_MON_STATE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 340

    EXP

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 341

    FLOAT

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 342

    FLOOR

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 343

    GETHINT

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 344

    GENERATE_UNIQUE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 345

    GRAPHIC

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 347

    HASHEDVALUE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 349

    HEX

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 351

    HOUR

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 353

    IDENTITY_VAL_LOCAL

    .

    .

    .

    .

    .

    .

    .

    .

    . 354

    INSERT

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 359

    INTEGER

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 360

    JULIAN_DAY

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 362

    LCASE

    or

    LOWER

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 363

    LCASE

    (SYSFUN

    schema)

    .

    .

    .

    .

    .

    .

    .

    .

    . 364

    LEFT

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 365

    LENGTH

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 366

    LN

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 367

    LOCATE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 368

    LOG

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 369

    LOG10

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 370

    LONG_VARCHAR

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 371

    LONG_VARGRAPHIC

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 372

    LTRIM

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 373

    LTRIM

    (SYSFUN

    schema)

    .

    .

    .

    .

    .

    .

    .

    .

    . 374

    MICROSECOND

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 375

    MIDNIGHT_SECONDS

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 376

    MINUTE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 377

    MOD

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 378

    MONTH

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 379

    MONTHNAME

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 380

    MULTIPLY_ALT

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 381

    NULLIF

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 383

    POSSTR

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 384

    POWER

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 386

    QUARTER

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 387

    RADIANS

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 388

    RAISE_ERROR

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 389

    RAND

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 390

    REAL

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 391

    REC2XML

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 392

    REPEAT

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 396

    REPLACE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 397

    RIGHT

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 398

    ROUND

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 399

    RTRIM

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 401

    RTRIM

    (SYSFUN

    schema)

    .

    .

    .

    .

    .

    .

    .

    .

    . 402

    SECOND

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 403

    SIGN

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 404

    SIN

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 405

    SINH

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 406

    SMALLINT

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 407

    SOUNDEX

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 408

    SPACE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 409

    SQRT

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 410

    SUBSTR

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 411

    TABLE_NAME

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 414

    TABLE_SCHEMA

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 415

    TAN

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 417

    TANH

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 418

    TIME

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 419

    TIMESTAMP

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 420

    TIMESTAMP_FORMAT

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 421

    TIMESTAMP_ISO

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 423

    TIMESTAMPDIFF

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 424

    TO_CHAR

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 426

    TO_DATE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 427

    TRANSLATE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 428

    TRUNCATE

    or

    TRUNC

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 430

    TYPE_ID

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 431

    TYPE_NAME

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 432

    TYPE_SCHEMA

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 433

    UCASE

    or

    UPPER

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 434

    VALUE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 435

    VARCHAR

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 436

    VARCHAR_FORMAT

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 438

    VARGRAPHIC

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 440

    WEEK

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 442

    WEEK_ISO

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 443

    YEAR

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 444

    Table

    functions

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 445

    Procedures

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 446

    User-defined

    functions

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 447

    Chapter

    4.

    Queries

    .

    .

    .

    .

    .

    .

    .

    .

    . 449

    SQL

    queries

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 449

    Subselect

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 450

    select-clause

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 450

    from-clause

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 454

    table-reference

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 454

    joined-table

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 461

    where-clause

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 463

    group-by-clause

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 463

    having-clause

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 469

    order-by-clause

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 470

    fetch-first-clause

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 472

    Examples

    of

    subselects

    .

    .

    .

    .

    .

    .

    .

    .

    . 473

    Examples

    of

    joins

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 475

    Examples

    of

    grouping

    sets,

    cube,

    and

    rollup

    .

    . 477

    Fullselect

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 485

    Examples

    of

    a

    fullselect

    .

    .

    .

    .

    .

    .

    .

    .

    . 487

    Select-statement

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 490

    common-table-expression

    .

    .

    .

    .

    .

    .

    .

    . 490

    Contents

    v

  • update-clause

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 495

    read-only-clause

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 496

    optimize-for-clause

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 496

    isolation-clause

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 497

    lock-request-clause

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 497

    Examples

    of

    a

    select-statement

    .

    .

    .

    .

    .

    . 498

    Appendix

    A.

    SQL

    limits

    .

    .

    .

    .

    .

    .

    . 501

    Appendix

    B.

    SQLCA

    (SQL

    communications

    area)

    .

    .

    .

    .

    .

    .

    . 507

    SQLCA

    field

    descriptions

    .

    .

    .

    .

    .

    .

    .

    .

    . 507

    Error

    reporting

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 510

    SQLCA

    usage

    in

    partitioned

    database

    systems

    .

    . 511

    Appendix

    C.

    SQLDA

    (SQL

    descriptor

    area)

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 513

    SQLDA

    field

    descriptions

    .

    .

    .

    .

    .

    .

    .

    .

    . 513

    Fields

    in

    the

    SQLDA

    header

    .

    .

    .

    .

    .

    .

    . 514

    Fields

    in

    an

    occurrence

    of

    a

    base

    SQLVAR

    .

    .

    . 515

    Fields

    in

    an

    occurrence

    of

    a

    secondary

    SQLVAR

    516

    Effect

    of

    DESCRIBE

    on

    the

    SQLDA

    .

    .

    .

    .

    .

    . 517

    SQLTYPE

    and

    SQLLEN

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 519

    Unrecognized

    and

    unsupported

    SQLTYPEs

    .

    . 520

    Packed

    decimal

    numbers

    .

    .

    .

    .

    .

    .

    .

    . 520

    SQLLEN

    field

    for

    decimal

    .

    .

    .

    .

    .

    .

    .

    . 521

    Appendix

    D.

    Catalog

    views

    .

    .

    .

    .

    . 523

    System

    catalog

    views

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 523

    Road

    map

    to

    the

    catalog

    views

    .

    .

    .

    .

    .

    .

    . 525

    SYSIBM.SYSDUMMY1

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 528

    SYSCAT.ATTRIBUTES

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 529

    SYSCAT.BUFFERPOOLDBPARTITIONS

    .

    .

    .

    . 530

    SYSCAT.BUFFERPOOLS

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 531

    SYSCAT.CASTFUNCTIONS

    .

    .

    .

    .

    .

    .

    .

    . 532

    SYSCAT.CHECKS

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 533

    SYSCAT.COLAUTH

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 534

    SYSCAT.COLCHECKS

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 535

    SYSCAT.COLDIST

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 536

    SYSCAT.COLGROUPDIST

    .

    .

    .

    .

    .

    .

    .

    .

    . 537

    SYSCAT.COLGROUPDISTCOUNTS

    .

    .

    .

    .

    .

    . 538

    SYSCAT.COLGROUPS

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 539

    SYSCAT.COLIDENTATTRIBUTES

    .

    .

    .

    .

    .

    . 540

    SYSCAT.COLOPTIONS

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 541

    SYSCAT.COLUMNS

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 542

    SYSCAT.COLUSE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 546

    SYSCAT.CONSTDEP

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 547

    SYSCAT.DATATYPES

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 548

    SYSCAT.DBAUTH

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 550

    SYSCAT.DBPARTITIONGROUPDEF

    .

    .

    .

    .

    .

    . 551

    SYSCAT.DBPARTITIONGROUPS

    .

    .

    .

    .

    .

    .

    . 552

    SYSCAT.EVENTMONITORS

    .

    .

    .

    .

    .

    .

    .

    . 553

    SYSCAT.EVENTS

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 554

    SYSCAT.EVENTTABLES

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 555

    SYSCAT.FULLHIERARCHIES

    .

    .

    .

    .

    .

    .

    .

    . 556

    SYSCAT.FUNCMAPOPTIONS

    .

    .

    .

    .

    .

    .

    .

    . 557

    SYSCAT.FUNCMAPPARMOPTIONS

    .

    .

    .

    .

    . 558

    SYSCAT.FUNCMAPPINGS

    .

    .

    .

    .

    .

    .

    .

    .

    . 559

    SYSCAT.HIERARCHIES

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 560

    SYSCAT.INDEXAUTH

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 561

    SYSCAT.INDEXCOLUSE

    .

    .

    .

    .

    .

    .

    .

    .

    . 562

    SYSCAT.INDEXDEP

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 563

    SYSCAT.INDEXES

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 564

    SYSCAT.INDEXEXPLOITRULES

    .

    .

    .

    .

    .

    .

    . 568

    SYSCAT.INDEXEXTENSIONDEP

    .

    .

    .

    .

    .

    .

    . 569

    SYSCAT.INDEXEXTENSIONMETHODS

    .

    .

    .

    . 570

    SYSCAT.INDEXEXTENSIONPARMS

    .

    .

    .

    .

    .

    . 571

    SYSCAT.INDEXEXTENSIONS

    .

    .

    .

    .

    .

    .

    .

    . 572

    SYSCAT.INDEXOPTIONS

    .

    .

    .

    .

    .

    .

    .

    .

    . 573

    SYSCAT.KEYCOLUSE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 574

    SYSCAT.NAMEMAPPINGS

    .

    .

    .

    .

    .

    .

    .

    . 575

    SYSCAT.PACKAGEAUTH

    .

    .

    .

    .

    .

    .

    .

    .

    . 576

    SYSCAT.PACKAGEDEP

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 577

    SYSCAT.PACKAGES

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 578

    SYSCAT.PARTITIONMAPS

    .

    .

    .

    .

    .

    .

    .

    .

    . 582

    SYSCAT.PASSTHRUAUTH

    .

    .

    .

    .

    .

    .

    .

    .

    . 583

    SYSCAT.PREDICATESPECS

    .

    .

    .

    .

    .

    .

    .

    . 584

    SYSCAT.PROCOPTIONS

    .

    .

    .

    .

    .

    .

    .

    .

    . 585

    SYSCAT.PROCPARMOPTIONS

    .

    .

    .

    .

    .

    .

    . 586

    SYSCAT.REFERENCES

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 587

    SYSCAT.REVTYPEMAPPINGS

    .

    .

    .

    .

    .

    .

    . 588

    SYSCAT.ROUTINEAUTH

    .

    .

    .

    .

    .

    .

    .

    .

    . 590

    SYSCAT.ROUTINEDEP

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 591

    SYSCAT.ROUTINEPARMS

    .

    .

    .

    .

    .

    .

    .

    .

    . 592

    SYSCAT.ROUTINES

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 594

    SYSCAT.SCHEMAAUTH

    .

    .

    .

    .

    .

    .

    .

    .

    . 600

    SYSCAT.SCHEMATA

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 601

    SYSCAT.SEQUENCEAUTH

    .

    .

    .

    .

    .

    .

    .

    .

    . 602

    SYSCAT.SEQUENCES

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 603

    SYSCAT.SERVEROPTIONS

    .

    .

    .

    .

    .

    .

    .

    .

    . 604

    SYSCAT.SERVERS

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 605

    SYSCAT.STATEMENTS

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 606

    SYSCAT.TABAUTH

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 607

    SYSCAT.TABCONST

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 609

    SYSCAT.TABDEP

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 610

    SYSCAT.TABLES

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 611

    SYSCAT.TABLESPACES

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 615

    SYSCAT.TABOPTIONS

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 616

    SYSCAT.TBSPACEAUTH

    .

    .

    .

    .

    .

    .

    .

    .

    . 617

    SYSCAT.TRANSFORMS

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 618

    SYSCAT.TRIGDEP

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 619

    SYSCAT.TRIGGERS

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 620

    SYSCAT.TYPEMAPPINGS

    .

    .

    .

    .

    .

    .

    .

    .

    . 621

    SYSCAT.USEROPTIONS

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 623

    SYSCAT.VIEWS

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 624

    SYSCAT.WRAPOPTIONS

    .

    .

    .

    .

    .

    .

    .

    .

    . 625

    SYSCAT.WRAPPERS

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 626

    SYSSTAT.COLDIST

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 627

    SYSSTAT.COLUMNS

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 628

    SYSSTAT.INDEXES

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 630

    SYSSTAT.ROUTINES

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 634

    SYSSTAT.TABLES

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 636

    Appendix

    E.

    Federated

    systems

    .

    .

    . 637

    Valid

    server

    types

    in

    SQL

    statements

    .

    .

    .

    .

    . 637

    BioRS

    wrapper

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 637

    BLAST

    wrapper

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 637

    CTLIB

    wrapper

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 638

    Documentum

    wrapper

    .

    .

    .

    .

    .

    .

    .

    .

    . 638

    DRDA

    wrapper

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 638

    Entrez

    wrapper

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 639

    vi

    SQL

    Reference,

    Volume

    1

    ||||

    ||

    |

    |

    |

    |

    |

    |

    |

    |

  • Excel

    wrapper

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 639

    Extended

    Search

    wrapper

    .

    .

    .

    .

    .

    .

    .

    . 639

    HMMER

    wrapper

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 639

    Informix

    wrapper

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 639

    MSSQLODBC3

    wrapper

    .

    .

    .

    .

    .

    .

    .

    .

    . 639

    NET8

    wrapper

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 640

    ODBC

    wrapper

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 640

    OLE

    DB

    wrapper

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 640

    Table-structured

    files

    wrapper

    .

    .

    .

    .

    .

    .

    . 640

    Teradata

    wrapper

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 640

    Web

    services

    wrapper

    .

    .

    .

    .

    .

    .

    .

    .

    . 640

    WebSphere

    Business

    Integration

    wrapper

    .

    .

    . 641

    XML

    wrapper

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 641

    Nickname

    column

    options

    for

    federated

    systems

    641

    Function

    mapping

    options

    for

    federated

    systems

    648

    Server

    options

    for

    federated

    systems

    .

    .

    .

    .

    . 648

    User

    mapping

    options

    for

    federated

    systems

    .

    .

    . 662

    Wrapper

    options

    for

    federated

    systems

    .

    .

    .

    .

    . 663

    Default

    forward

    data

    type

    mappings

    .

    .

    .

    .

    . 663

    DB2

    for

    z/OS

    and

    OS/390

    data

    sources

    .

    .

    . 664

    DB2

    for

    iSeries

    data

    sources

    .

    .

    .

    .

    .

    .

    . 665

    DB2

    Server

    for

    VM

    and

    VSE

    data

    sources

    .

    .

    . 666

    DB2

    for

    Linux,

    UNIX,

    and

    Windows

    data

    sources

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 667

    Informix

    data

    sources

    .

    .

    .

    .

    .

    .

    .

    .

    . 668

    Microsoft

    SQL

    Server

    data

    sources

    .

    .

    .

    .

    . 669

    ODBC

    data

    sources

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 672

    Oracle

    NET8

    data

    sources

    .

    .

    .

    .

    .

    .

    .

    . 673

    Sybase

    data

    sources

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 674

    Teradata

    data

    sources

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 675

    Default

    reverse

    data

    type

    mappings

    .

    .

    .

    .

    .

    . 677

    DB2

    for

    z/OS

    and

    OS/390

    data

    sources

    .

    .

    . 678

    DB2

    for

    iSeries

    data

    sources

    .

    .

    .

    .

    .

    .

    . 679

    DB2

    for

    VM

    and

    VSE

    data

    sources

    .

    .

    .

    .

    . 680

    DB2

    for

    Linux,

    UNIX,

    and

    Windows

    data

    sources

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 681

    Informix

    data

    sources

    .

    .

    .

    .

    .

    .

    .

    .

    . 682

    Microsoft

    SQL

    Server

    data

    sources

    .

    .

    .

    .

    . 683

    Oracle

    NET8

    data

    sources

    .

    .

    .

    .

    .

    .

    .

    . 684

    Sybase

    data

    sources

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 685

    Teradata

    data

    sources

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 686

    Appendix

    F.

    The

    SAMPLE

    database

    687

    Creating

    the

    SAMPLE

    database

    .

    .

    .

    .

    .

    .

    . 687

    Erasing

    the

    SAMPLE

    database

    .

    .

    .

    .

    .

    .

    .

    . 687

    CL_SCHED

    table

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 687

    DEPARTMENT

    table

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 687

    EMPLOYEE

    table

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 688

    EMP_ACT

    table

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 690

    EMP_PHOTO

    table

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 691

    EMP_RESUME

    table

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 692

    IN_TRAY

    table

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 692

    ORG

    table

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 692

    PROJECT

    table

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 693

    SALES

    table

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 693

    STAFF

    table

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 694

    STAFFG

    table

    (double-byte

    code

    pages

    only)

    .

    .

    . 695

    Sample

    files

    with

    BLOB

    and

    CLOB

    data

    type

    .

    .

    . 696

    Quintana

    photo

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 696

    Quintana

    resume

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 697

    Nicholls

    photo

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 698

    Nicholls

    resume

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 698

    Adamson

    photo

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 699

    Adamson

    resume

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 699

    Walker

    photo

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 700

    Walker

    resume

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 700

    Appendix

    G.

    Reserved

    schema

    names

    and

    reserved

    words

    .

    .

    .

    .

    .

    .

    .

    . 703

    Appendix

    H.

    Interaction

    of

    triggers

    and

    constraints

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 707

    Appendix

    I.

    Explain

    tables

    .

    .

    .

    .

    .

    . 709

    Explain

    tables

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 709

    EXPLAIN_ARGUMENT

    table

    .

    .

    .

    .

    .

    .

    .

    . 710

    EXPLAIN_INSTANCE

    table

    .

    .

    .

    .

    .

    .

    .

    . 714

    EXPLAIN_OBJECT

    table

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 716

    EXPLAIN_OPERATOR

    table

    .

    .

    .

    .

    .

    .

    .

    . 719

    EXPLAIN_PREDICATE

    table

    .

    .

    .

    .

    .

    .

    .

    . 721

    EXPLAIN_STATEMENT

    table

    .

    .

    .

    .

    .

    .

    .

    . 723

    EXPLAIN_STREAM

    table

    .

    .

    .

    .

    .

    .

    .

    .

    . 725

    ADVISE_INDEX

    table

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 727

    ADVISE_INSTANCE

    table

    .

    .

    .

    .

    .

    .

    .

    .

    . 730

    ADVISE_MQT

    table

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 731

    ADVISE_PARTITION

    table

    .

    .

    .

    .

    .

    .

    .

    .

    . 732

    ADVISE_TABLE

    table

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 733

    ADVISE_WORKLOAD

    table

    .

    .

    .

    .

    .

    .

    .

    . 734

    Appendix

    J.

    Explain

    register

    values

    735

    Appendix

    K.

    Exception

    tables

    .

    .

    .

    . 741

    Rules

    for

    creating

    an

    exception

    table

    .

    .

    .

    .

    . 741

    Handling

    rows

    in

    an

    exception

    table

    .

    .

    .

    .

    . 743

    Querying

    exception

    tables

    .

    .

    .

    .

    .

    .

    .

    .

    . 743

    Appendix

    L.

    SQL

    statements

    allowed

    in

    routines

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 745

    Appendix

    M.

    CALL

    invoked

    from

    a

    compiled

    statement

    .

    .

    .

    .

    .

    .

    .

    .

    . 749

    Appendix

    N.

    Japanese

    and

    traditional-Chinese

    extended

    UNIX

    code

    (EUC)

    considerations

    .

    .

    .

    .

    . 755

    Language

    elements

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 755

    Characters

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 755

    Tokens

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 755

    Identifiers

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 755

    Data

    types

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 755

    Constants

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 757

    Functions

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 758

    Expressions

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 758

    Predicates

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 758

    Functions

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 759

    LENGTH

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 759

    SUBSTR

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 759

    TRANSLATE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 759

    VARGRAPHIC

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 759

    Contents

    vii

    ||||||

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

    ||

    ||

    ||

    ||||

    |

    |

    |

    |

    |

    |

    |

    |

  • Statements

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 760

    CONNECT

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 760

    PREPARE

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 760

    Appendix

    O.

    Backus-Naur

    form

    (BNF)

    specifications

    for

    DATALINKs

    .

    .

    .

    . 761

    Appendix

    P.

    DB2

    Universal

    Database

    technical

    information

    .

    .

    .

    .

    .

    .

    .

    . 763

    DB2

    documentation

    and

    help

    .

    .

    .

    .

    .

    .

    .

    . 763

    DB2

    documentation

    updates

    .

    .

    .

    .

    .

    .

    . 763

    DB2

    Information

    Center

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 764

    DB2

    Information

    Center

    installation

    scenarios

    .

    . 765

    Installing

    the

    DB2

    Information

    Center

    using

    the

    DB2

    Setup

    wizard

    (UNIX)

    .

    .

    .

    .

    .

    .

    .

    .

    . 768

    Installing

    the

    DB2

    Information

    Center

    using

    the

    DB2

    Setup

    wizard

    (Windows)

    .

    .

    .

    .

    .

    .

    .

    . 770

    Invoking

    the

    DB2

    Information

    Center

    .

    .

    .

    .

    . 772

    Updating

    the

    DB2

    Information

    Center

    installed

    on

    your

    computer

    or

    intranet

    server

    .

    .

    .

    .

    .

    .

    . 773

    Displaying

    topics

    in

    your

    preferred

    language

    in

    the

    DB2

    Information

    Center

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 774

    DB2

    PDF

    and

    printed

    documentation

    .

    .

    .

    .

    . 775

    Core

    DB2

    information

    .

    .

    .

    .

    .

    .

    .

    .

    . 775

    Administration

    information

    .

    .

    .

    .

    .

    .

    . 775

    Application

    development

    information

    .

    .

    .

    . 776

    Business

    intelligence

    information

    .

    .

    .

    .

    .

    . 777

    DB2

    Connect

    information

    .

    .

    .

    .

    .

    .

    .

    . 777

    Getting

    started

    information

    .

    .

    .

    .

    .

    .

    .

    . 778

    Tutorial

    information

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 778

    Optional

    component

    information

    .

    .

    .

    .

    .

    . 778

    Release

    notes

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 779

    Printing

    DB2

    books

    from

    PDF

    files

    .

    .

    .

    .

    .

    . 780

    Ordering

    printed

    DB2

    books

    .

    .

    .

    .

    .

    .

    .

    . 780

    Invoking

    contextual

    help

    from

    a

    DB2

    tool

    .

    .

    .

    . 781

    Invoking

    message

    help

    from

    the

    command

    line

    processor

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 782

    Invoking

    command

    help

    from

    the

    command

    line

    processor

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 783

    Invoking

    SQL

    state

    help

    from

    the

    command

    line

    processor

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 783

    DB2

    tutorials

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 783

    DB2

    troubleshooting

    information

    .

    .

    .

    .

    .

    .

    . 784

    Accessibility

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 785

    Keyboard

    input

    and

    navigation

    .

    .

    .

    .

    .

    . 785

    Accessible

    display

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 785

    Compatibility

    with

    assistive

    technologies

    .

    .

    . 786

    Accessible

    documentation

    .

    .

    .

    .

    .

    .

    .

    . 786

    Dotted

    decimal

    syntax

    diagrams

    .

    .

    .

    .

    .

    .

    . 786

    Common

    Criteria

    certification

    of

    DB2

    Universal

    Database

    products

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 788

    Appendix

    Q.

    Notices

    .

    .

    .

    .

    .

    .

    .

    . 789

    Trademarks

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 791

    Index

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 793

    Contacting

    IBM

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 809

    Product

    information

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    . 809

    viii

    SQL

    Reference,

    Volume

    1

    ||

    ||||||||

    |||

    ||

    |

    |

    |

    |

    |

    |

    |

    |

    |

    |

    |

    |

    |

    |

  • About

    this

    book

    The

    SQL

    Reference

    in

    its

    two

    volumes

    defines

    the

    SQL

    language

    used

    by

    DB2

    Universal

    Database

    Version

    8,

    and

    includes:

    v

    Information

    about

    relational

    database

    concepts,

    language

    elements,

    functions,

    and

    the

    forms

    of

    queries

    (Volume

    1).

    v

    Information

    about

    the

    syntax

    and

    semantics

    of

    SQL

    statements

    (Volume

    2).

    Who

    should

    use

    this

    book

    This

    book

    is

    intended

    for

    anyone

    who

    wants

    to

    use

    the

    Structured

    Query

    Language

    (SQL)

    to

    access

    a

    database.

    It

    is

    primarily

    for

    programmers

    and

    database

    administrators,

    but

    it

    can

    also

    be

    used

    by

    those

    who

    access

    databases

    through

    the

    command

    line

    processor

    (CLP).

    This

    book

    is

    a

    reference

    rather

    than

    a

    tutorial.

    It

    assumes

    that

    you

    will

    be

    writing

    application

    programs

    and

    therefore

    presents

    the

    full

    functions

    of

    the

    database

    manager.

    How

    this

    book

    is

    structured

    This

    book

    contains

    information

    about

    the

    following

    major

    topics:

    v

    Chapter

    1,

    Concepts,

    on

    page

    1

    discusses

    the

    basic

    concepts

    of

    relational

    databases

    and

    SQL.

    v

    Chapter

    2,

    Language

    elements,

    on

    page

    55

    describes

    the

    basic

    syntax

    of

    SQL

    and

    the

    language

    elements

    that

    are

    common

    to

    many

    SQL

    statements.

    v

    Chapter

    3,

    Functions,

    on

    page

    225

    contains

    syntax

    diagrams,

    semantic

    descriptions,

    rules,

    and

    usage

    examples

    of

    SQL

    column

    and

    scalar

    functions.

    v

    Chapter

    4,

    Queries,

    on

    page

    449

    describes

    the

    various

    forms

    of

    a

    query.

    v

    Appendix

    A,

    SQL

    limits,

    on

    page

    501

    lists

    SQL

    limitations.

    v

    Appendix

    B,

    SQLCA

    (SQL

    communications

    area),

    on

    page

    507

    describes

    the

    SQLCA

    structure.

    v

    Appendix

    C,

    SQLDA

    (SQL

    descriptor

    area),

    on

    page

    513

    describes

    the

    SQLDA

    structure.

    v

    Appendix

    D,

    Catalog

    views,

    on

    page

    523

    describes

    the

    database

    catalog

    views.

    v

    Appendix

    E,

    Federated

    systems,

    on

    page

    637

    describes

    options

    and

    type

    mappings

    for

    Federated

    Systems.

    v

    Appendix

    F,

    The

    SAMPLE

    database,

    on

    page

    687

    describes

    the

    sample

    tables

    used

    in

    examples.

    v

    Appendix

    G,

    Reserved

    schema

    names

    and

    reserved

    words,

    on

    page

    703

    contains

    the

    reserved

    schema

    names

    and

    the

    reserved

    words

    for

    the

    IBM

    SQL

    and

    ISO/ANSI

    SQL99

    standards.

    v

    Appendix

    H,

    Interaction

    of

    triggers

    and

    constraints,

    on

    page

    707

    discusses

    the

    interaction

    of

    triggers

    and

    referential

    constraints.

    v

    Appendix

    I,

    Explain

    tables,

    on

    page

    709

    describes

    the

    Explain

    tables.

    v

    Appendix

    J,

    Explain

    register

    values,

    on

    page

    735

    describes

    the

    interaction

    of

    the

    CURRENT

    EXPLAIN

    MODE

    and

    CURRENT

    EXPLAIN

    SNAPSHOT

    special

    register

    values

    with

    each

    other

    and

    with

    the

    PREP

    and

    BIND

    commands.

    Copyright

    IBM

    Corp.

    1993

    -

    2004

    ix

  • v

    Appendix

    K,

    Exception

    tables,

    on

    page

    741

    contains

    information

    about

    user-created

    tables

    that

    are

    used

    with

    the

    SET

    INTEGRITY

    statement.

    v

    Appendix

    L,

    SQL

    statements

    allowed

    in

    routines,

    on

    page

    745

    lists

    the

    SQL

    statements

    that

    are

    allowed

    to

    execute

    in

    routines

    with

    different

    SQL

    data

    access

    contexts.

    v

    Appendix

    M,

    CALL

    invoked

    from

    a

    compiled

    statement,

    on

    page

    749

    describes

    the

    CALL

    statement

    that

    can

    be

    invoked

    from

    a

    compiled

    statement.

    v

    Appendix

    N,

    Japanese

    and

    traditional-Chinese

    extended

    UNIX

    code

    (EUC)

    considerations,

    on

    page

    755

    lists

    considerations

    when

    using

    extended

    UNIX

    code

    (EUC)

    character

    sets.

    v

    Appendix

    O,

    Backus-Naur

    form

    (BNF)

    specifications

    for

    DATALINKs,

    on

    page

    761

    contains

    the

    Backus-Naur

    form

    (BNF)

    specifications

    for

    DATALINKs.

    A

    brief

    overview

    of

    Volume

    2

    The

    second

    volume

    of

    the

    SQL

    Reference

    contains

    information

    about

    the

    syntax

    and

    semantics

    of

    SQL

    statements.

    The

    specific

    chapters

    in

    that

    volume

    are

    briefly

    described

    here:

    v

    SQL

    statements

    contains

    syntax

    diagrams,

    semantic

    descriptions,

    rules,

    and

    examples

    of

    all

    SQL

    statements.

    v

    SQL

    control

    statements

    contains

    syntax

    diagrams,

    semantic

    descriptions,

    rules,

    and

    examples

    of

    SQL

    procedure

    statements.

    How

    to

    read

    the

    syntax

    diagrams

    Throughout

    this

    book,

    syntax

    is

    described

    using

    the

    structure

    defined

    as

    follows:

    Read

    the

    syntax

    diagrams

    from

    left

    to

    right

    and

    top

    to

    bottom,

    following

    the

    path

    of

    the

    line.

    The

    symbol

    indicates

    the

    beginning

    of

    a

    syntax

    diagram.

    The

    symbol

    indicates

    that

    the

    syntax

    is

    continued

    on

    the

    next

    line.

    The

    symbol

    indicates

    that

    the

    syntax

    is

    continued

    from

    the

    previous

    line.

    The

    symbol

    indicates

    the

    end

    of

    a

    syntax

    diagram.

    Syntax

    fragments

    start

    with

    the

    symbol

    and

    end

    with

    the

    symbol.

    Required

    items

    appear

    on

    the

    horizontal

    line

    (the

    main

    path).

    required_item

    Optional

    items

    appear

    below

    the

    main

    path.

    required_item

    optional_item

    If

    an

    optional

    item

    appears

    above

    the

    main

    path,

    that

    item

    has

    no

    effect

    on

    execution,

    and

    is

    used

    only

    for

    readability.

    How

    this

    book

    is

    structured

    x

    SQL

    Reference,

    Volume

    1

  • required_item

    optional_item

    If

    you

    can

    choose

    from

    two

    or

    more

    items,

    they

    appear

    in

    a

    stack.

    If

    you

    must

    choose

    one

    of

    the

    items,

    one

    item

    of

    the

    stack

    appears

    on

    the

    main

    path.

    required_item

    required_choice1

    required_choice2

    If

    choosing

    one

    of

    the

    items

    is

    optional,

    the

    entire

    stack

    appears

    below

    the

    main

    path.

    required_item

    optional_choice1

    optional_choice2

    If

    one

    of

    the

    items

    is

    the

    default,

    it

    will

    appear

    above

    the

    main

    path,

    and

    the

    remaining

    choices

    will

    be

    shown

    below.

    required_item

    default_choice

    optional_choice

    optional_choice

    An

    arrow

    returning

    to

    the

    left,

    above

    the

    main

    line,

    indicates

    an

    item

    that

    can

    be

    repeated.

    In

    this

    case,

    repeated

    items

    must

    be

    separated

    by

    one

    or

    more

    blanks.

    required_item

    repeatable_item

    If

    the

    repeat

    arrow

    contains

    a

    comma,

    you

    must

    separate

    repeated

    items

    with

    a

    comma.

    required_item

    ,

    repeatable_item

    A

    repeat

    arrow

    above

    a

    stack

    indicates

    that

    you

    can

    make

    more

    than

    one

    choice

    from

    the

    stacked

    items

    or

    repeat

    a

    single

    choice.

    Keywords

    appear

    in

    uppercase

    (for

    example,

    FROM).

    They

    must

    be

    spelled

    exactly

    as

    shown.

    Variables

    appear

    in

    lowercase

    (for

    example,

    column-name).

    They

    represent

    user-supplied

    names

    or

    values

    in

    the

    syntax.

    If

    punctuation

    marks,

    parentheses,

    arithmetic

    operators,

    or

    other

    such

    symbols

    are

    shown,

    you

    must

    enter

    them

    as

    part

    of

    the

    syntax.

    How

    to

    read

    the

    syntax

    diagrams

    About

    this

    book

    xi

  • Sometimes

    a

    single

    variable

    represents

    a

    larger

    fragment

    of

    the

    syntax.

    For

    example,

    in

    the

    following

    diagram,

    the

    variable

    parameter-block

    represents

    the

    whole

    syntax

    fragment

    that

    is

    labeled

    parameter-block:

    required_item

    parameter-block

    parameter-block:

    parameter1

    parameter2

    parameter3

    parameter4

    Adjacent

    segments

    occurring

    between

    large

    bullets

    (*)

    may

    be

    specified

    in

    any

    sequence.

    required_item

    item1

    *

    item2

    *

    item3

    *

    item4

    The

    above

    diagram

    shows

    that

    item2

    and

    item3

    may

    be

    specified

    in

    either

    order.

    Both

    of

    the

    following

    are

    valid:

    required_item

    item1

    item2

    item3

    item4

    required_item

    item1

    item3

    item2

    item4

    Common

    syntax

    elements

    The

    following

    sec