sql user guide - broadcom inc. datacom...updated a tables to include signed columns (see data type...
TRANSCRIPT
-
SQL User Guide Version 15.00
CA Datacom®/DB
-
This Documentation, which includes embedded help systems and electronically distributed materials, (hereinafter referred to as the “Documentation”) is for your informational purposes only and is subject to change or withdrawal by CA at any time.
This Documentation may not be copied, transferred, reproduced, disclosed, modified or duplicated, in whole or in part, without the prior written consent of CA. This Documentation is confidential and proprietary information of CA and may not be disclosed by you or used for any purpose other than as may be permitted in (i) a separate agreement between you and CA governing your use of the CA software to which the Documentation relates; or (ii) a separate confidentiality agreement between you and CA.
Notwithstanding the foregoing, if you are a licensed user of the software product(s) addressed in the Documentation, you may print or otherwise make available a reasonable number of copies of the Documentation for internal use by you and your employees in connection with that software, provided that all CA copyright notices and legends are affixed to each reproduced copy.
The right to print or otherwise make available copies of the Documentation is limited to the period during which the applicable license for such software remains in full force and effect. Should the license terminate for any reason, it is your responsibility to certify in writing to CA that all copies and partial copies of the Documentation have been returned to CA or destroyed.
TO THE EXTENT PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS DOCUMENTATION “AS IS” WITHOUT WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NONINFRINGEMENT. IN NO EVENT WILL CA BE LIABLE TO YOU OR ANY THIRD PARTY FOR ANY LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS DOCUMENTATION, INCLUDING WITHOUT LIMITATION, LOST PROFITS, LOST INVESTMENT, BUSINESS INTERRUPTION, GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH LOSS OR DAMAGE.
The use of any software product referenced in the Documentation is governed by the applicable license agreement and such license agreement is not modified in any way by the terms of this notice.
The manufacturer of this Documentation is CA.
Provided with “Restricted Rights.” Use, duplication or disclosure by the United States Government is subject to the restrictions set forth in FAR Sections 12.212, 52.227-14, and 52.227-19(c)(1) - (2) and DFARS Section 252.227-7014(b)(3), as applicable, or their successors.
Copyright © 2014 CA. All rights reserved. All trademarks, trade names, service marks, and logos referenced herein belong to their respective companies.
-
CA Technologies Product References
This document references the following CA products:
■ CA Datacom®/DB
■ CA Datacom® CICS Services
■ CA Datacom® Datadictionary™
■ CA Datacom® DB2 Transparency
■ CA Datacom® DL1 Transparency
■ CA Datacom® IMS/DC Services
■ CA Datacom® Server
■ CA Datacom® SQL (SQL)
■ CA Datacom® STAR
■ CA Datacom® TOTAL Transparency
■ CA Datacom® VSAM Transparency
■ CA Dataquery™ for CA Datacom® (CA Dataquery)
■ CA Ideal™ for CA Datacom® (CA Ideal)
■ CA IPC
■ CA Librarian®
■ CA Common Services for z/OS
-
Contact CA Technologies
Contact CA Support
For your convenience, CA Technologies provides one site where you can access the information that you need for your Home Office, Small Business, and Enterprise CA Technologies products. At http://ca.com/support, you can access the following resources:
■ Online and telephone contact information for technical assistance and customer services
■ Information about user communities and forums
■ Product and documentation downloads
■ CA Support policies and guidelines
■ Other helpful resources appropriate for your product
Providing Feedback About Product Documentation
If you have comments or questions about CA Technologies product documentation, you can send a message to [email protected].
To provide feedback about CA Technologies product documentation, complete our short customer survey which is available on the CA Support website at http://ca.com/docs.
http://www.ca.com/supportmailto:[email protected]://ca.com/docshttp://ca.com/docs
-
Documentation Changes
The following documentation updates have been made since the last release of this documen tation.
This guide has been appropriately revised with additions and updates that include the following:
■ added ALTER AREA (see page 600) statement
■ updated ALTER TABLE (see page 602) statement
■ added ALTER DATABASE (see page 601) statement
■ added CREATE AREA (see page 623) statement
■ added CREATE DATABASE (see page 625) statement
■ updated DECLARE CURSOR (see page 720) statement
■ added DROP AREA (see page 739) statement
■ added DROP DATABASE (see page 740) statement
■ added SQL Databases (see page 43) section
■ added SQL Areas (see page 43) section
■ added UNSIGNED to the column definition options for ALTER TABLE (see page 606)
■ added UNSIGNED to the column definition options for CREATE TABLE (see the CREATE TABLE column definition (see page 693))
■ added information about DBSQLPR-related message DB00248I (see DBSQLPR (see page 117))
■ added a performance enhancement comment to COUNT(*) (see Counting (see page 324))
■ added the REPLACE function (see Character Functions (see page 566))
■ added the POSSTR function (see Character Functions (see page 566))
■ converted the SQL-related DIAGOPTION 1,64 to a MUF startup option SQL_ALLOW_TIME_240000 (see the CA Datacom/DB Database and System Administration Guide)
■ added a QUERYNO option to the Select-Statement (see page 783)
■ updated a tables to include signed columns (see Data Type of the Column, Null Value, and Sign) (see page 877)
■ updated a tables to include signed columns (see SQLDA (EXECUTE, FETCH, or OPEN Statement) (see page 879)
-
Contents 7
Contents
Chapter 1: Introduction 23
System Tasks .............................................................................................................................................................. 23
Syntax Diagrams ......................................................................................................................................................... 23
CA Datacom/DB Extensions ....................................................................................................................................... 23
Where to Find Information ........................................................................................................................................ 23
Related Publications ................................................................................................................................................... 23
Listing Libraries for CA Datacom Products ................................................................................................................. 24
Sample Report Headers .............................................................................................................................................. 24
CA Datacom/DB Extensions ....................................................................................................................................... 26
Chapter 2: Before You Start 27
What Is SQL? .............................................................................................................................................................. 27
What You Should Know About SQL ............................................................................................................................ 27
Tables .................................................................................................................................................................. 27
Columns .............................................................................................................................................................. 27
Rows .................................................................................................................................................................... 28
Views ................................................................................................................................................................... 28
Table and View Examples .................................................................................................................................... 28
Indexes ................................................................................................................................................................ 30
Cursors ................................................................................................................................................................ 30
Units of Work ...................................................................................................................................................... 30
Units of Recovery (Logical Unit of Work) ............................................................................................................ 30
Isolation Levels .................................................................................................................................................... 31
Schemas .............................................................................................................................................................. 33
Authorization ID .................................................................................................................................................. 33
Accessor ID .......................................................................................................................................................... 33
Privileges ............................................................................................................................................................. 34
Synonym .............................................................................................................................................................. 34
SQL Statements ................................................................................................................................................... 35
Binding ................................................................................................................................................................ 37
Plan ..................................................................................................................................................................... 37
SQL Manager .............................................................................................................................................................. 38
Reserved Words ......................................................................................................................................................... 39
Chapter 3: Getting Started 43
SQL Schemas .............................................................................................................................................................. 43
-
8 SQL User Guide
SQL Databases ............................................................................................................................................................ 43
SQL Areas ................................................................................................................................................................... 43
SQL Tables .................................................................................................................................................................. 44
SQL Tables and Logging ....................................................................................................................................... 44
Creating SQL Tables ............................................................................................................................................. 44
Using Existing Tables ........................................................................................................................................... 45
Populating SQL Tables ................................................................................................................................................ 47
Accessing SQL Tables .................................................................................................................................................. 47
Selecting and Manipulating Data ............................................................................................................................... 47
Specifying Preprocessor Options ................................................................................................................................ 48
Preparing Programs .................................................................................................................................................... 48
Mixed Mode Programming ................................................................................................................................. 49
Statement Execution Table ........................................................................................................................................ 49
Dynamic SQL............................................................................................................................................................... 51
Static SQL ............................................................................................................................................................ 52
Dynamic SQL ....................................................................................................................................................... 52
Dynamic SQL in CA Datacom/DB ......................................................................................................................... 53
INCLUDE Directive ............................................................................................................................................... 53
Name Types ......................................................................................................................................................... 54
Reserved Words .................................................................................................................................................. 54
Parameter Markers ............................................................................................................................................. 54
Security Implications of Dynamic SQL ................................................................................................................. 54
Using Dynamic SQL in Application Programs ...................................................................................................... 54
Other Tasks................................................................................................................................................................. 65
SQL Status Tables ....................................................................................................................................................... 66
Procedures and Triggers ............................................................................................................................................. 66
Overview ............................................................................................................................................................. 67
SQL Procedures ................................................................................................................................................... 70
External Security Support for Procedure/Trigger Creation and Execution ......................................................... 70
Trigger Execution for Record-at-a-Time Maintenance ........................................................................................ 71
Transaction Integrity ........................................................................................................................................... 71
Subroutine Calls Inside Procedures ..................................................................................................................... 72
Restrictions ......................................................................................................................................................... 72
Multi-User Facility Considerations for Procedures ............................................................................................. 73
Parameter Styles and Error Handling .................................................................................................................. 76
SQL Error Messages Related to Procedures and Triggers ................................................................................... 79
Datadictionary Support for Triggers and Procedures ......................................................................................... 82
Examples: Creating a Procedure ......................................................................................................................... 83
Example: Calling a Procedure ............................................................................................................................ 105
Left Outer Joins ........................................................................................................................................................ 106
Overview of Joins .............................................................................................................................................. 106
SELECT Statement Subselect Syntax ................................................................................................................. 107
-
Contents 9
SELECT Statement Select-Into Syntax ............................................................................................................... 108
Inner Join Example ............................................................................................................................................ 108
Outer Join Example ........................................................................................................................................... 108
Value of Rows That Do Not Match .................................................................................................................... 109
WHERE Clause ................................................................................................................................................... 110
Performance Considerations ............................................................................................................................. 111
Order of Predicate Evaluation ........................................................................................................................... 112
SQL Memory Guard .................................................................................................................................................. 113
Activating the SQL Memory Guard ................................................................................................................... 114
SQL and Multiple Multi-User Facilities Support ....................................................................................................... 115
Application Design Considerations ........................................................................................................................... 115
Index-Only Processing ....................................................................................................................................... 116
Cursor Processing .............................................................................................................................................. 116
DBSQLPR ................................................................................................................................................................... 117
Processing ......................................................................................................................................................... 118
Line Commands ................................................................................................................................................. 118
DBSQLPR Syntax ................................................................................................................................................ 119
DBSQLPR Options .............................................................................................................................................. 119
DROP PLAN (DBSQLPR) ..................................................................................................................................... 128
Example JCL ....................................................................................................................................................... 129
Sample Report ................................................................................................................................................... 131
DATACOM VIEWs ..................................................................................................................................................... 132
Overview ........................................................................................................................................................... 132
Redefinitions ..................................................................................................................................................... 132
Arrays ................................................................................................................................................................ 135
Default Values for Redefinitions and Arrays ..................................................................................................... 136
Datadictionary Considerations .......................................................................................................................... 137
Using SQC Table to Cancel SQL Requests ................................................................................................................. 137
Overriding SQL Key Selection ................................................................................................................................... 137
Examples ........................................................................................................................................................... 139
XML Support ...................................................................................................................................................... 139
SQL Read-Only .......................................................................................................................................................... 140
SQL Source Cache ..................................................................................................................................................... 141
Chapter 4: CA Datacom/DB SQL Preprocessors 143
Input to the Preprocessor ........................................................................................................................................ 144
INCLUDEs in COBOL ........................................................................................................................................... 145
INCLUDEs in PL/I ................................................................................................................................................ 145
INCLUDEs in Assembler ..................................................................................................................................... 145
INCLUDEs in C .................................................................................................................................................... 146
Output from the Preprocessors ............................................................................................................................... 146
-
10 SQL User Guide
COBOL ............................................................................................................................................................... 146
PL/I, Assembler, and C ...................................................................................................................................... 147
Sample JCL ................................................................................................................................................................ 147
Sample COBOL JCL............................................................................................................................................. 148
Sample PL/I JCL ................................................................................................................................................. 157
Sample Assembler JCL ....................................................................................................................................... 159
Sample C Language JCL ..................................................................................................................................... 164
Embedding SQL Statements in Host Programs ........................................................................................................ 169
Distinguishing SQL Statements ......................................................................................................................... 169
Rules for Coding Embedded SQL ....................................................................................................................... 172
Coding Embedded SQL in COBOL ...................................................................................................................... 174
Coding Embedded SQL in PL/I ........................................................................................................................... 181
Coding Embedded SQL in Assembler ................................................................................................................ 196
Coding Embedded SQL in C ............................................................................................................................... 202
Using Preprocessor Options ..................................................................................................................................... 204
Overview ........................................................................................................................................................... 205
Naming the Plan ................................................................................................................................................ 205
Specifying Processing Options in COBOL .......................................................................................................... 206
Specifying Processing Options in PL/I, C, and Assembler .................................................................................. 207
Options You Can Specify ................................................................................................................................... 210
Description of Options ...................................................................................................................................... 213
SQL Communication Area (SQLCA) ........................................................................................................................... 237
SQLCA in COBOL ................................................................................................................................................ 237
SQLCA in PL/I ..................................................................................................................................................... 237
SQLCA in Assembler .......................................................................................................................................... 238
SQLCA in C Language ......................................................................................................................................... 238
Example SQLCA Formats ................................................................................................................................... 238
SQL Work Area (SQLWA) .......................................................................................................................................... 256
SQLWA Examples .............................................................................................................................................. 256
Error Handling .......................................................................................................................................................... 263
Interaction of Multiple Preprocessors ..................................................................................................................... 264
SQL Plan Options Special Topics ............................................................................................................................... 265
Read-Only .......................................................................................................................................................... 265
Mixing Isolation Levels ...................................................................................................................................... 265
Locking a Row .................................................................................................................................................... 265
CICS Unit of Recovery End ................................................................................................................................. 266
ANSI Compatibility ............................................................................................................................................ 267
CA Ideal Considerations .................................................................................................................................... 268
Block Transfer ................................................................................................................................................... 268
OPEN/CLOSE Efficiency ..................................................................................................................................... 268
Automatic Unit of Recovery End ....................................................................................................................... 268
Plan Locks .......................................................................................................................................................... 269
-
Contents 11
Plan Locks .......................................................................................................................................................... 271
Chapter 5: Interfacing with the User Requirements Table (URT) 275
DBURINF - User Requirements Interface ................................................................................................................. 276
DBURSTR - Start User Requirements Table .............................................................................................................. 277
DBUREND - End Interface/Table .............................................................................................................................. 277
Example .................................................................................................................................................................... 277
Chapter 6: Program Compilation, Link-Edit and Execution 279
Batch Link-Editing and Execution ............................................................................................................................. 279
Linking Multiple Modules with SQL .......................................................................................................................... 279
Sample JCL for Batch ................................................................................................................................................ 282
CICS Link-Editing and Execution ............................................................................................................................... 282
Sample JCL for CICS .................................................................................................................................................. 283
IMS/DC Link-Editing and Execution .......................................................................................................................... 283
Sample JCL for IMS/DC ............................................................................................................................................. 283
z/OS IMS/DC Sample JCL ................................................................................................................................... 284
Chapter 7: SQL Error Handling 287
SQL Return Codes -117 and -118 .............................................................................................................................. 287
Online Displays ......................................................................................................................................................... 290
Batch Output ............................................................................................................................................................ 294
Error Handling Related to Procedures and Triggers ................................................................................................. 296
SQL States ................................................................................................................................................................. 296
SQLCA Examples ................................................................................................................................................ 296
SQL State Classes ............................................................................................................................................... 304
SQL States Table ................................................................................................................................................ 306
Chapter 8: Application Tasks Using Embedded SQL 315
Chapter 9: Specifying Result Tables 319
Selecting All Columns ............................................................................................................................................... 319
Selecting Some Columns .......................................................................................................................................... 320
Selecting Using Search Conditions ........................................................................................................................... 321
Ordering by Column Values ...................................................................................................................................... 322
Eliminating Duplicate Rows ...................................................................................................................................... 323
Counting ................................................................................................................................................................... 324
Calculating Values .................................................................................................................................................... 325
Summarizing Group Values ...................................................................................................................................... 327
-
12 SQL User Guide
Testing for Existence ................................................................................................................................................ 329
Chapter 10: Selecting Data from Multiple Tables 331
Joining Tables ........................................................................................................................................................... 331
Using the UNION Operator ...................................................................................................................................... 334
Chapter 11: Inserting Rows 339
Chapter 12: Updating a Table 341
Chapter 13: Deleting Rows 345
Chapter 14: Committing and Backing Out Transactions 347
Chapter 15: Overview of the Interactive SQL Service Facility 349
Chapter 16: Using the Interactive SQL Service Facility 353
Executable SQL Statements ...................................................................................................................................... 354
Specifying Unique SQL Names.................................................................................................................................. 354
Submitting SQL Statements ...................................................................................................................................... 355
How to Submit SQL Statements ........................................................................................................................ 356
How to Use ........................................................................................................................................................ 357
Using Commands ...................................................................................................................................................... 364
Commands Specifically for Use in the Interactive SQL Service Facility ............................................................. 366
ALTERNATE Command ...................................................................................................................................... 366
COPY SQL Command ......................................................................................................................................... 366
DELETE SQL Command ...................................................................................................................................... 368
DISPLAY SQL Command ..................................................................................................................................... 369
EDIT SQL Command ........................................................................................................................................... 370
EXECUTE Command .......................................................................................................................................... 371
REBIND Command ............................................................................................................................................. 371
SCROLL Command ............................................................................................................................................. 372
Using Line Commands .............................................................................................................................................. 373
Using Margin Commands ......................................................................................................................................... 374
Using PF Keys ............................................................................................................................................................ 375
Maintaining Source and Output Members .............................................................................................................. 377
Editing and Executing Source Members ........................................................................................................... 378
Displaying Source and Output Members .......................................................................................................... 386
Copying Source Members ................................................................................................................................. 391
-
Contents 13
Deleting Source and Output Members ............................................................................................................. 393
Chapter 17: Creating SQL Objects 397
Creating a Schema .................................................................................................................................................... 398
Naming the Schema .......................................................................................................................................... 399
Relating the Person to the AUTHID ................................................................................................................... 399
Changing Your AUTHID ...................................................................................................................................... 400
System Schemas ................................................................................................................................................ 401
Displaying and Reporting .................................................................................................................................. 401
Example Source Member .................................................................................................................................. 402
Example Output Member ................................................................................................................................. 403
Chapter 18: Creating a Database 405
Chapter 19: Creating an Area 407
Creating a Table ....................................................................................................................................................... 407
Naming the Table .............................................................................................................................................. 408
Key Creation ...................................................................................................................................................... 409
Element Creation .............................................................................................................................................. 410
Statement Execution Results ............................................................................................................................ 411
Example Source Member .................................................................................................................................. 411
Example Output Member ................................................................................................................................. 413
Altering a Table ........................................................................................................................................................ 414
Statement Execution Results ............................................................................................................................ 415
Example Source Member .................................................................................................................................. 415
Example Output Member ................................................................................................................................. 416
Creating an Index ..................................................................................................................................................... 417
Naming the Index (Key) ..................................................................................................................................... 418
Key Creation ...................................................................................................................................................... 418
Statement Execution Results ............................................................................................................................ 418
Example Source Member .................................................................................................................................. 419
Example Output Member ................................................................................................................................. 420
Creating a View ........................................................................................................................................................ 421
Naming the View ............................................................................................................................................... 421
Example Source Member .................................................................................................................................. 422
Example Output Member ................................................................................................................................. 424
Creating a Synonym ................................................................................................................................................. 425
Naming the Synonym ........................................................................................................................................ 426
Example Source Member .................................................................................................................................. 427
Example Output Member ................................................................................................................................. 428
-
14 SQL User Guide
Adding and Replacing Comments ............................................................................................................................ 429
Example Source Member .................................................................................................................................. 429
Example Output Member ................................................................................................................................. 430
Chapter 20: Deleting SQL Objects 433
Deleting a Schema .................................................................................................................................................... 434
Dropping an Index .................................................................................................................................................... 434
Dropping a Table ...................................................................................................................................................... 436
Dropping a View ....................................................................................................................................................... 439
Dropping a Synonym ................................................................................................................................................ 441
Chapter 21: Manipulating Data in SQL Tables 445
Chapter 22: Controlling Access Through SQL Statements 447
Chapter 23: Performing SQL Administrative Tasks 449
SQL Names ............................................................................................................................................................... 449
Setting the Session Authorization ID ........................................................................................................................ 450
Current Authorization ID at Start of Session ..................................................................................................... 450
Displaying and Reporting .................................................................................................................................. 451
How to Set the Default ...................................................................................................................................... 452
Deleting a Plan ......................................................................................................................................................... 454
How the Plan Is Named ..................................................................................................................................... 455
How to Delete a Plan ......................................................................................................................................... 456
Rebinding a Plan ....................................................................................................................................................... 459
How to Rebind a Plan ........................................................................................................................................ 459
Displaying Index of SQL Plans ................................................................................................................................... 462
How to Display an Index of SQL Plans ............................................................................................................... 463
Specifying Plan Options in a Source Member .......................................................................................................... 465
Coding Plan Options ................................................................................................................................................. 466
Options You Can Specify ................................................................................................................................... 469
Example ............................................................................................................................................................. 475
Chapter 24: Overview of SQL Language Reference 477
Chapter 25: Basic Language Elements 479
Characters ................................................................................................................................................................ 479
Tokens ...................................................................................................................................................................... 479
Spaces ............................................................................................................................................................... 480
-
Contents 15
Uppercase and Lowercase ................................................................................................................................ 480
Identifiers ................................................................................................................................................................. 480
Ordinary SQL identifiers .................................................................................................................................... 481
Delimited SQL identifiers .................................................................................................................................. 481
Naming Conventions ................................................................................................................................................ 482
Authorization ID ....................................................................................................................................................... 485
Values ....................................................................................................................................................................... 486
Data Types ................................................................................................................................................................ 487
DATE, TIME, and TIMESTAMP ........................................................................................................................... 487
Host Variable Data Types .................................................................................................................................. 488
SQL Data Types .................................................................................................................................................. 488
CA Datacom/DB Data Types .............................................................................................................................. 488
SQL Data Type Support for All CA Datacom/DB Tables ..................................................................................... 492
Character Strings ............................................................................................................................................... 497
Numeric Data Types .......................................................................................................................................... 502
Basic Operations (Assignment and Comparison) ..................................................................................................... 503
Numeric Assignments ....................................................................................................................................... 504
String Assignment ............................................................................................................................................. 507
Numeric Comparisons ....................................................................................................................................... 509
String Comparisons ........................................................................................................................................... 511
Literals ...................................................................................................................................................................... 512
Character String Literals .................................................................................................................................... 512
Integer Literals .................................................................................................................................................. 514
Floating Point Literals ........................................................................................................................................ 515
Decimal Literals ................................................................................................................................................. 515
Column Names ......................................................................................................................................................... 516
Qualified Column Names .................................................................................................................................. 517
Correlation Names ............................................................................................................................................ 517
Column-Name Qualifiers to Avoid Ambiguity ................................................................................................... 519
Column-Name Qualifiers in Correlated References .......................................................................................... 520
Host Variables .......................................................................................................................................................... 522
Host Structures ................................................................................................................................................. 522
Extended Format for Host Variables in COBOL ................................................................................................. 524
Indicator Variables ................................................................................................................................................... 526
SQL Parameters ........................................................................................................................................................ 527
SQL Variables ............................................................................................................................................................ 527
Chapter 26: Expressions 529
CASE, COALESCE, NULLIF, and CAST ......................................................................................................................... 531
Special Registers ....................................................................................................................................................... 535
Labeled Duration ...................................................................................................................................................... 537
-
16 SQL User Guide
Expressions without Arithmetic Operators .............................................................................................................. 539
Expressions with the Concatenation Operator ........................................................................................................ 539
Expressions with Arithmetic Operators ................................................................................................................... 540
Arithmetic Operations for Dates, Times, and Timestamps ...................................................................................... 544
Durations ........................................................................................................................................................... 544
Precedence of Operations ........................................................................................................................................ 548
Chapter 27: Functions 551
Column Functions ..................................................................................................................................................... 551
Description ........................................................................................................................................................ 551
Rules for Column Functions .............................................................................................................................. 552
Examples ........................................................................................................................................................... 554
Scalar Functions ....................................................................................................................................................... 555
Rules for Scalar Functions ................................................................................................................................. 556
Description ........................................................................................................................................................ 556
Character Functions .......................................................................................................................................... 566
Bit-Level Functions ............................................................................................................................................ 572
Byte-Level Function ........................................................................................................................................... 576
XML Functions ................................................................................................................................................... 577
Chapter 28: Predicates 583
Basic Predicate ......................................................................................................................................................... 583
Quantified Predicate ................................................................................................................................................ 585
BETWEEN Predicate ................................................................................................................................................. 586
LIKE Predicate ........................................................................................................................................................... 587
EXISTS Predicate ....................................................................................................................................................... 591
IN Predicate .............................................................................................................................................................. 592
NULL Predicate ......................................................................................................................................................... 594
Chapter 29: Search Conditions 595
Chapter 30: SQL Statements 599
Preliminary Information—Lock Levels ..................................................................................................................... 599
Statements That Support Procedures and Triggers ................................................................................................. 599
ALTER AREA .............................................................................................................................................................. 600
Description ........................................................................................................................................................ 601
ALTER DATABASE ..................................................................................................................................................... 601
Description ........................................................................................................................................................ 602
ALTER TABLE ............................................................................................................................................................. 602
Description ........................................................................................................................................................ 606
-
Contents 17
Processing ......................................................................................................................................................... 611
Assignment Statement ............................................................................................................................................. 615
CALL/EXECUTE PROCEDURE ..................................................................................................................................... 615
CASE Statement ........................................................................................................................................................ 617
CLOSE ....................................................................................................................................................................... 617
Description ........................................................................................................................................................ 618
Processing ......................................................................................................................................................... 618
COMMENT ON.......................................................................................................................................................... 618
Description ........................................................................................................................................................ 619
COMMIT WORK ........................................................................................................................................................ 621
Description ........................................................................................................................................................ 621
CREATE AREA ............................................................................................................................................................ 623
Description ........................................................................................................................................................ 624
CREATE DATABASE ................................................................................................................................................... 625
Description ........................................................................................................................................................ 627
CREATE INDEX .......................................................................................................................................................... 627
Description ........................................................................................................................................................ 629
Processing ......................................................................................................................................................... 630
CREATE PROCEDURE ................................................................................................................................................ 630
External Procedures .......................................................................................................................................... 632
SQL Procedures ................................................................................................................................................. 632
CREATE PROCEDURE Syntax and Description ................................................................................................... 634
CREATE RULE ............................................................................................................................................................ 686
CREATE SCHEMA ...................................................................................................................................................... 686
Description ........................................................................................................................................................ 687
CREATE SYNONYM ................................................................................................................................................... 688
Description ........................................................................................................................................................ 689
CREATE TABLE .......................................................................................................................................................... 690
Description ........................................................................................................................................................ 691
Privileges ........................................................................................................................................................... 692
Column Definition ............................................................................................................................................. 693
Column Constraint Definition ........................................................................................................................... 695
Table Constraint Definition ............................................................................................................................... 697
Referential Constraint Definition ...................................................................................................................... 699
Data Types ......................................................................................................................................................... 705
CREATE TRIGGER/RULE ............................................................................................................................................ 712
CREATE VIEW ............................................................................................................................................................ 715
Privileges ........................................................................................................................................................... 716
Description ........................................................................................................................................................ 717
Processing ......................................................................................................................................................... 718
DECLARE CURSOR ..................................................................................................................................................... 720
Description ........................................................................................................................................................ 721
-
18 SQL User Guide
Cursor Usage ..................................................................................................................................................... 722
Example1 ........................................................................................................................................................... 723
Example 2 .......................................................................................................................................................... 724
Example 3 .......................................................................................................................................................... 724
DECLARE STATEMENT .............................................................................................................................................. 725
DELETE ...................................................................................................................................................................... 725
Searched DELETE ............................................................................................................................................... 726
Positioned DELETE ............................................................................................................................................. 726
Description ........................................................................................................................................................ 727
Processing ......................................................................................................................................................... 728
DESCRIBE .................................................................................................................................................................. 729
Description ........................................................................................................................................................ 731
DROP ........................................................................................................................................................................ 733
Description ........................................................................................................................................................ 736
Example 1 .......................................................................................................................................................... 739
Example 2 .......................................................................................................................................................... 739
Example 3 .......................................................................................................................................................... 739
DROP AREA ............................................................................................................................................................... 739
Description ........................................................................................................................................................ 740
DROP DATABASE ...................................................................................................................................................... 740
Description ........................................................................................................................................................ 741
EXECUTE ................................................................................................................................................................... 741
Description ........................................................................................................................................................ 742
Parameter Marker Replacement ...................................................................................................................... 743
EXECUTE IMMEDIATE ............................................................................................................................................... 744
Description ........................................................................................................................................................ 745
Rules for Statement Strings .............................................................................................................................. 745
EXECUTE PROCEDURE .............................................................................................................................................. 745
FETCH ....................................................................................................................................................................... 745
Description ........................................................................................................................................................ 746
Processing ......................................................................................................................................................... 747
GRANT ...................................................................................................................................................................... 748
Plan Security ...................................................................................................................................................... 748
Description of Plan Security Diagram ................................................................................................................ 749
Description of Non-Plan Security Diagram ........................................................................................................ 750
IF-THEN Statement ................................................................................................................................................... 752
INSERT ...................................................................................................................................................................... 753
Description ........................................................................................................................................................ 754
Rules for Inserting ............................................................................................................................................. 755
Processing ......................................................................................................................................................... 755
ITERATE Statement ................................................................................................................................................... 756
LEAVE Statement ...................................................................................................................................................... 756
-
Contents 19
LOCK TABLE .............................................................................................................................................................. 757
Description ........................................................................................................................................................ 757
Example ............................................................................................................................................................. 758
LOOP Statement ....................................................................................................................................................... 758
OPEN ........................................................................................................................................................................ 758
Description ........................................................................................................................................................ 759
Processing ......................................................................................................................................................... 761
Effect of Temporary Tables ............................................................................................................................... 761
Example ............................................................................................................................................................. 761
PREPARE ................................................................................................................................................................... 762
Description ........................................................................................................................................................ 763
Rules for Statement Strings .............................................................................................................................. 764
Rules for Parameter Markers ............................................................................................................................ 764
REPEAT-UNTIL Statement ......................................................................................................................................... 765
REVOKE ..................................................................................................................................................................... 765
Plan Security ...................................................................................................................................................... 766
Description of Plan Security Diagram ................................................................................................................ 766
Description of Non-Plan Security Diagram ........................................................................................................ 768
Example 1 .......................................................................................................................................................... 769
Example 2 .......................................................................................................................................................... 770
Example 3 .......................................................................................................................................................... 770
ROLLBACK WORK ...................................................................................................................................................... 770
Description ........................................................................................................................................................ 771
SELECT ...................................................................................................................................................................... 772
Subselect ........................................................................................................................................................... 773
Full-Select Statement ........................................................................................................................................ 781
Description ........................................................................................................................................................ 782
Select-Statement ............................................................................................................................................... 783
ORDER BY Clause ............................................................................................................................................... 785
Select-Into Statement ....................................................................................................................................... 787
SET CURRENT SQLID ................................................................................................................................................. 793
Description ........................................................................................................................................................ 794
Example ............................................................................................................................................................. 795
UPDATE .................................................................................................................................................................... 795
Searched UPDATE ............................................................................................................................................. 796
Positioned UPDATE ........................................................................................................................................... 796
WHENEVER ............................................................................................................................................................... 800
Description ........................................................................................................................................................ 800
Processing ......................................................................................................................................................... 801
Example ............................................................................................................................................................. 802
WHILE Statement ..................................................................................................................................................... 802
-
20 SQL User Guide
Appendix A: SQL Query Optimization Messages 803
Message Table (SYSADM.SYSMSG) .......................................................................................................................... 803
Requesting Messages ............................................................................................................................................... 804
Bind-time Messages ................................................................................................................................................. 804
Bind-time Summary Messages .......................................................................................................................... 804
Bind-time Detail Messages ................................................................................................................................ 813
Execution-Time Messages ........................................................................................................................................ 818
Execution-Time Summary Messages ................................................................................................................ 819
Execution-Time Detail Messages ...................................................................................................................... 822
Examples ............................................