CA Datacom®/DB Datacom 14... · CA Technologies Product References This document references the following CA products: CA Datacom®/DB CA Datacom® CICS Services A Datacom® Datadictionary™
Post on 18-Mar-2020
5 Views
Preview:
Transcript
SQL User Guide Version 14.02
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 © 2015 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 techpubs@ca.com.
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:techpubs@ca.comhttp://ca.com/docshttp://ca.com/docs
Contents 5
Contents
Chapter 1: Introduction 21
System Tasks .............................................................................................................................................................. 21
Syntax Diagrams ......................................................................................................................................................... 21
CA Datacom/DB Extensions ....................................................................................................................................... 21
Where to Find Information ........................................................................................................................................ 21
Related Publications ................................................................................................................................................... 21
Listing Libraries for CA Datacom Products ................................................................................................................. 22
Sample Report Headers.............................................................................................................................................. 22
Reading Syntax Diagrams ........................................................................................................................................... 24
Statement Without Parameters .......................................................................................................................... 25
Statement with Required Parameters ................................................................................................................ 25
Delimiters Around Parameters ........................................................................................................................... 25
Choice of Required Parameters .......................................................................................................................... 26
Default Value for a Required Parameter ............................................................................................................. 26
Optional Parameter............................................................................................................................................. 26
Choice of Optional Parameters ........................................................................................................................... 27
Repeatable Variable Parameter .......................................................................................................................... 27
Separator with Repeatable Variable and Delimiter ............................................................................................ 27
Optional Repeatable Parameters ........................................................................................................................ 28
Default Value for a Parameter ............................................................................................................................ 28
Variables Representing Several Parameters ....................................................................................................... 29
CA Datacom/DB Extensions ....................................................................................................................................... 29
Chapter 2: Before You Start 31
What Is SQL? .............................................................................................................................................................. 31
What You Should Know About SQL ............................................................................................................................ 31
Tables .................................................................................................................................................................. 31
Columns .............................................................................................................................................................. 31
Rows .................................................................................................................................................................... 32
Views ................................................................................................................................................................... 32
Table and View Examples .................................................................................................................................... 32
Indexes ................................................................................................................................................................ 34
Cursors ................................................................................................................................................................ 34
Units of Work ...................................................................................................................................................... 34
Units of Recovery (Logical Unit of Work) ............................................................................................................ 34
Isolation Levels .................................................................................................................................................... 35
6 SQL User Guide
Schemas .............................................................................................................................................................. 37
Authorization ID .................................................................................................................................................. 37
Accessor ID .......................................................................................................................................................... 37
Privileges ............................................................................................................................................................. 38
Synonym .............................................................................................................................................................. 38
SQL Statements ................................................................................................................................................... 39
Binding ................................................................................................................................................................ 41
Plan ..................................................................................................................................................................... 41
SQL Manager .............................................................................................................................................................. 42
Reserved Words ......................................................................................................................................................... 43
Chapter 3: Getting Started 47
SQL Schemas .............................................................................................................................................................. 47
SQL Tables .................................................................................................................................................................. 47
SQL Tables and Logging ....................................................................................................................................... 48
Creating SQL Tables............................................................................................................................................. 48
Using Existing Tables ........................................................................................................................................... 49
Populating SQL Tables ................................................................................................................................................ 50
Accessing SQL Tables .................................................................................................................................................. 51
Selecting and Manipulating Data ............................................................................................................................... 51
Specifying Preprocessor Options ................................................................................................................................ 52
Preparing Programs .................................................................................................................................................... 52
Mixed Mode Programming ................................................................................................................................. 53
Statement Execution Table ........................................................................................................................................ 53
Dynamic SQL............................................................................................................................................................... 55
Static SQL ............................................................................................................................................................ 56
Dynamic SQL ....................................................................................................................................................... 56
Dynamic SQL in CA Datacom/DB ......................................................................................................................... 57
INCLUDE Directive ............................................................................................................................................... 57
Name Types ......................................................................................................................................................... 58
Reserved Words .................................................................................................................................................. 58
Parameter Markers ............................................................................................................................................. 58
Security Implications of Dynamic SQL ................................................................................................................. 58
Using Dynamic SQL in Application Programs ...................................................................................................... 58
Other Tasks................................................................................................................................................................. 69
SQL Status Tables ....................................................................................................................................................... 70
Procedures and Triggers ............................................................................................................................................. 70
Overview ............................................................................................................................................................. 71
SQL Procedures ................................................................................................................................................... 74
External Security Support for Procedure/Trigger Creation and Execution ......................................................... 74
Trigger Execution for Record-at-a-Time Maintenance ........................................................................................ 75
Contents 7
Transaction Integrity ........................................................................................................................................... 75
Subroutine Calls Inside Procedures ..................................................................................................................... 76
Restrictions ......................................................................................................................................................... 76
Multi-User Facility Considerations for Procedures ............................................................................................. 77
Parameter Styles and Error Handling .................................................................................................................. 80
SQL Error Messages Related to Procedures and Triggers ................................................................................... 83
Datadictionary Support for Triggers and Procedures ......................................................................................... 86
Examples: Creating a Procedure ......................................................................................................................... 87
Example: Calling a Procedure ............................................................................................................................ 109
Left Outer Joins ........................................................................................................................................................ 110
Overview of Joins .............................................................................................................................................. 110
SELECT Statement Subselect Syntax ................................................................................................................. 111
SELECT Statement Select-Into Syntax ............................................................................................................... 112
Inner Join Example ............................................................................................................................................ 112
Outer Join Example ........................................................................................................................................... 112
Value of Rows That Do Not Match .................................................................................................................... 113
WHERE Clause ................................................................................................................................................... 114
Performance Considerations ............................................................................................................................. 115
Order of Predicate Evaluation ........................................................................................................................... 116
SQL Memory Guard .................................................................................................................................................. 117
Activating the SQL Memory Guard ................................................................................................................... 118
SQL and Multiple Multi-User Facilities Support ....................................................................................................... 119
Application Design Considerations ........................................................................................................................... 119
Index-Only Processing ....................................................................................................................................... 120
Cursor Processing .............................................................................................................................................. 120
DBSQLPR ................................................................................................................................................................... 121
Processing ......................................................................................................................................................... 122
Line Commands ................................................................................................................................................. 122
DBSQLPR Syntax ................................................................................................................................................ 123
DBSQLPR Options .............................................................................................................................................. 123
DROP PLAN (DBSQLPR) ..................................................................................................................................... 132
Example JCL ....................................................................................................................................................... 133
Example SQL Statements .................................................................................................................................. 135
Sample Report ................................................................................................................................................... 137
DATACOM VIEWs ..................................................................................................................................................... 138
Overview ........................................................................................................................................................... 138
Redefinitions ..................................................................................................................................................... 138
Arrays ................................................................................................................................................................ 141
Default Values for Redefinitions and Arrays ..................................................................................................... 142
Datadictionary Considerations .......................................................................................................................... 143
Using SQC Table to Cancel SQL Requests ................................................................................................................. 143
Overriding SQL Key Selection ................................................................................................................................... 143
8 SQL User Guide
Examples ........................................................................................................................................................... 145
XML Support...................................................................................................................................................... 145
SQL Read-Only .......................................................................................................................................................... 146
Chapter 4: CA Datacom/DB SQL Preprocessors 147
Input to the Preprocessor ........................................................................................................................................ 148
INCLUDEs in COBOL ........................................................................................................................................... 149
INCLUDEs in PL/I ................................................................................................................................................ 149
INCLUDEs in Assembler ..................................................................................................................................... 149
INCLUDEs in C .................................................................................................................................................... 150
Output from the Preprocessors ............................................................................................................................... 150
COBOL ............................................................................................................................................................... 150
PL/I, Assembler, and C ...................................................................................................................................... 151
Sample JCL ................................................................................................................................................................ 151
Sample COBOL JCL............................................................................................................................................. 152
Sample PL/I JCL ................................................................................................................................................. 161
Sample Assembler JCL ....................................................................................................................................... 163
Sample C Language JCL ..................................................................................................................................... 168
Embedding SQL Statements in Host Programs ........................................................................................................ 173
Distinguishing SQL Statements ......................................................................................................................... 173
Rules for Coding Embedded SQL ....................................................................................................................... 176
Coding Embedded SQL in COBOL ...................................................................................................................... 178
Coding Embedded SQL in PL/I ........................................................................................................................... 185
Coding Embedded SQL in Assembler ................................................................................................................ 200
Coding Embedded SQL in C ............................................................................................................................... 206
Using Preprocessor Options ..................................................................................................................................... 208
Overview ........................................................................................................................................................... 209
Naming the Plan ................................................................................................................................................ 209
Specifying Processing Options in COBOL .......................................................................................................... 210
Specifying Processing Options in PL/I, C, and Assembler .................................................................................. 211
Options You Can Specify ................................................................................................................................... 214
Description of Options ...................................................................................................................................... 217
SQL Communication Area (SQLCA) ........................................................................................................................... 242
SQLCA in COBOL ................................................................................................................................................ 242
SQLCA in PL/I ..................................................................................................................................................... 242
SQLCA in Assembler .......................................................................................................................................... 243
SQLCA in C Language ......................................................................................................................................... 243
Example SQLCA Formats ................................................................................................................................... 243
SQL Work Area (SQLWA) .......................................................................................................................................... 261
SQLWA Examples .............................................................................................................................................. 261
Error Handling .......................................................................................................................................................... 268
Contents 9
Interaction of Multiple Preprocessors ..................................................................................................................... 269
SQL Plan Options Special Topics ............................................................................................................................... 270
Read-Only .......................................................................................................................................................... 270
Mixing Isolation Levels ...................................................................................................................................... 270
Locking a Row.................................................................................................................................................... 270
CICS Unit of Recovery End ................................................................................................................................. 271
ANSI Compatibility ............................................................................................................................................ 272
CA Ideal Considerations .................................................................................................................................... 273
Block Transfer ................................................................................................................................................... 273
OPEN/CLOSE Efficiency ..................................................................................................................................... 273
Automatic Unit of Recovery End ....................................................................................................................... 273
Plan Locks .......................................................................................................................................................... 274
Chapter 5: Interfacing with the User Requirements Table (URT) 277
DBURINF - User Requirements Interface ................................................................................................................. 278
DBURSTR - Start User Requirements Table .............................................................................................................. 279
DBUREND - End Interface/Table .............................................................................................................................. 279
Example .................................................................................................................................................................... 279
Chapter 6: Program Compilation, Link-Edit and Execution 281
Batch Link-Editing and Execution ............................................................................................................................. 281
Linking Multiple Modules with SQL .......................................................................................................................... 281
Sample JCL for Batch ................................................................................................................................................ 284
CICS Link-Editing and Execution ............................................................................................................................... 284
Sample JCL for CICS .................................................................................................................................................. 285
IMS/DC Link-Editing and Execution .......................................................................................................................... 285
Sample JCL for IMS/DC ............................................................................................................................................. 285
z/OS IMS/DC Sample JCL ................................................................................................................................... 286
Chapter 7: SQL Error Handling 289
SQL Return Codes -117 and -118.............................................................................................................................. 289
Online Displays ......................................................................................................................................................... 292
Batch Output ............................................................................................................................................................ 296
Error Handling Related to Procedures and Triggers ................................................................................................. 298
SQL States ................................................................................................................................................................. 298
SQLCA Examples ................................................................................................................................................ 298
SQL State Classes ............................................................................................................................................... 306
SQL States Table ................................................................................................................................................ 308
10 SQL User Guide
Chapter 8: Application Tasks Using Embedded SQL 317
Chapter 9: Specifying Result Tables 321
Selecting All Columns ............................................................................................................................................... 321
Selecting Some Columns .......................................................................................................................................... 322
Selecting Using Search Conditions ........................................................................................................................... 323
Ordering by Column Values...................................................................................................................................... 324
Eliminating Duplicate Rows ...................................................................................................................................... 325
Counting ................................................................................................................................................................... 326
Calculating Values .................................................................................................................................................... 327
Summarizing Group Values ...................................................................................................................................... 329
Testing for Existence ................................................................................................................................................ 331
Chapter 10: Selecting Data from Multiple Tables 333
Joining Tables ........................................................................................................................................................... 334
Using the UNION Operator ...................................................................................................................................... 337
Chapter 11: Inserting Rows 341
Chapter 12: Updating a Table 343
Chapter 13: Deleting Rows 347
Chapter 14: Committing and Backing Out Transactions 349
Chapter 15: Overview of the Interactive SQL Service Facility 351
Chapter 16: Using the Interactive SQL Service Facility 355
Executable SQL Statements ...................................................................................................................................... 356
Specifying Unique SQL Names.................................................................................................................................. 356
Submitting SQL Statements ...................................................................................................................................... 357
How to Submit SQL Statements ........................................................................................................................ 358
How to Use ........................................................................................................................................................ 359
Using Commands...................................................................................................................................................... 366
Commands Specifically for Use in the Interactive SQL Service Facility ............................................................. 368
ALTERNATE Command ...................................................................................................................................... 368
COPY SQL Command ......................................................................................................................................... 368
DELETE SQL Command ...................................................................................................................................... 370
Contents 11
DISPLAY SQL Command ..................................................................................................................................... 371
EDIT SQL Command ........................................................................................................................................... 372
EXECUTE Command .......................................................................................................................................... 373
REBIND Command ............................................................................................................................................. 373
SCROLL Command ............................................................................................................................................. 374
Using Line Commands .............................................................................................................................................. 375
Using Margin Commands ......................................................................................................................................... 376
Using PF Keys ............................................................................................................................................................ 377
Maintaining Source and Output Members .............................................................................................................. 379
Editing and Executing Source Members ........................................................................................................... 380
Displaying Source and Output Members .......................................................................................................... 388
Copying Source Members ................................................................................................................................. 393
Deleting Source and Output Members ............................................................................................................. 395
Chapter 17: Creating SQL Objects 399
Creating a Schema .................................................................................................................................................... 400
Naming the Schema .......................................................................................................................................... 400
Relating the Person to the AUTHID ................................................................................................................... 401
Changing Your AUTHID...................................................................................................................................... 402
System Schemas ................................................................................................................................................ 402
Displaying and Reporting .................................................................................................................................. 403
Example Source Member .................................................................................................................................. 403
Example Output Member ................................................................................................................................. 405
Creating a Table ....................................................................................................................................................... 405
Naming the Table .............................................................................................................................................. 406
Key Creation ...................................................................................................................................................... 407
Element Creation .............................................................................................................................................. 408
Statement Execution Results ............................................................................................................................ 409
Example Source Member .................................................................................................................................. 409
Example Output Member ................................................................................................................................. 411
Altering a Table ........................................................................................................................................................ 412
Statement Execution Results ............................................................................................................................ 413
Example Source Member .................................................................................................................................. 413
Example Output Member ................................................................................................................................. 414
Creating an Index ..................................................................................................................................................... 415
Naming the Index (Key) ..................................................................................................................................... 416
Key Creation ...................................................................................................................................................... 416
Statement Execution Results ............................................................................................................................ 416
Example Source Member .................................................................................................................................. 417
Example Output Member ................................................................................................................................. 418
Creating a View ........................................................................................................................................................ 419
12 SQL User Guide
Naming the View ............................................................................................................................................... 419
Example Source Member .................................................................................................................................. 420
Example Output Member ................................................................................................................................. 422
Creating a Synonym ................................................................................................................................................. 423
Naming the Synonym ........................................................................................................................................ 424
Example Source Member .................................................................................................................................. 425
Example Output Member ................................................................................................................................. 426
Adding and Replacing Comments ............................................................................................................................ 427
Example Source Member .................................................................................................................................. 427
Example Output Member ................................................................................................................................. 428
Chapter 18: Deleting SQL Objects 431
Deleting a Schema .................................................................................................................................................... 432
Dropping an Index .................................................................................................................................................... 432
Dropping a Table ...................................................................................................................................................... 434
Dropping a View ....................................................................................................................................................... 437
Dropping a Synonym ................................................................................................................................................ 439
Chapter 19: Manipulating Data in SQL Tables 443
Chapter 20: Controlling Access Through SQL Statements 445
Chapter 21: Performing SQL Administrative Tasks 447
SQL Names ............................................................................................................................................................... 447
Setting the Session Authorization ID ........................................................................................................................ 448
Current Authorization ID at Start of Session ..................................................................................................... 448
Displaying and Reporting .................................................................................................................................. 449
How to Set the Default ...................................................................................................................................... 450
Deleting a Plan ......................................................................................................................................................... 452
How the Plan Is Named ..................................................................................................................................... 453
How to Delete a Plan ......................................................................................................................................... 454
Rebinding a Plan ....................................................................................................................................................... 457
How to Rebind a Plan ........................................................................................................................................ 457
Displaying Index of SQL Plans ................................................................................................................................... 460
How to Display an Index of SQL Plans ............................................................................................................... 461
Specifying Plan Options in a Source Member .......................................................................................................... 463
Coding Plan Options ................................................................................................................................................. 464
Options You Can Specify ................................................................................................................................... 467
Example ............................................................................................................................................................. 473
Contents 13
Chapter 22: Overview of SQL Language Reference 475
Chapter 23: Basic Language Elements 477
Characters ................................................................................................................................................................ 477
Tokens ...................................................................................................................................................................... 477
Spaces ............................................................................................................................................................... 478
Uppercase and Lowercase ................................................................................................................................ 478
Identifiers ................................................................................................................................................................. 478
Ordinary SQL identifiers .................................................................................................................................... 479
Delimited SQL identifiers .................................................................................................................................. 479
Naming Conventions ................................................................................................................................................ 480
Authorization ID ....................................................................................................................................................... 483
Values ....................................................................................................................................................................... 484
Data Types ................................................................................................................................................................ 485
DATE, TIME, and TIMESTAMP ........................................................................................................................... 485
Host Variable Data Types .................................................................................................................................. 486
SQL Data Types .................................................................................................................................................. 486
CA Datacom/DB Data Types .............................................................................................................................. 486
SQL Data Type Support for All CA Datacom/DB Tables ..................................................................................... 490
Character Strings ............................................................................................................................................... 495
Numeric Data Types .......................................................................................................................................... 500
Basic Operations (Assignment and Comparison) ..................................................................................................... 501
Numeric Assignments ....................................................................................................................................... 502
String Assignment ............................................................................................................................................. 505
Numeric Comparisons ....................................................................................................................................... 507
String Comparisons ........................................................................................................................................... 509
Literals ...................................................................................................................................................................... 510
Character String Literals .................................................................................................................................... 510
Integer Literals .................................................................................................................................................. 512
Floating Point Literals ........................................................................................................................................ 513
Decimal Literals ................................................................................................................................................. 513
Column Names ......................................................................................................................................................... 514
Qualified Column Names .................................................................................................................................. 515
Correlation Names ............................................................................................................................................ 515
Column-Name Qualifiers to Avoid Ambiguity ................................................................................................... 517
Column-Name Qualifiers in Correlated References .......................................................................................... 518
Host Variables .......................................................................................................................................................... 520
Host Structures ................................................................................................................................................. 520
Extended Format for Host Variables in COBOL ................................................................................................. 522
Indicator Variables ................................................................................................................................................... 524
SQL Parameters ........................................................................................................................................................ 525
14 SQL User Guide
SQL Variables ............................................................................................................................................................ 525
Chapter 24: Expressions 527
CASE, COALESCE, NULLIF, and CAST ......................................................................................................................... 529
Special Registers ....................................................................................................................................................... 533
Labeled Duration ...................................................................................................................................................... 535
Expressions without Arithmetic Operators .............................................................................................................. 537
Expressions with the Concatenation Operator ........................................................................................................ 537
Expressions with Arithmetic Operators ................................................................................................................... 538
Arithmetic Operations for Dates, Times, and Timestamps ...................................................................................... 542
Durations ........................................................................................................................................................... 542
Precedence of Operations ........................................................................................................................................ 546
Chapter 25: Functions 549
Column Functions ..................................................................................................................................................... 549
Description ........................................................................................................................................................ 549
Rules for Column Functions .............................................................................................................................. 551
Examples ........................................................................................................................................................... 553
Scalar Functions ....................................................................................................................................................... 554
Rules for Scalar Functions ................................................................................................................................. 555
Description ........................................................................................................................................................ 555
Character Functions .......................................................................................................................................... 565
Bit-Level Functions ............................................................................................................................................ 570
Byte-Level Function ........................................................................................................................................... 573
XML Functions ................................................................................................................................................... 574
Chapter 26: Predicates 581
Basic Predicate ......................................................................................................................................................... 581
Quantified Predicate ................................................................................................................................................ 583
BETWEEN Predicate ................................................................................................................................................. 584
LIKE Predicate ........................................................................................................................................................... 585
EXISTS Predicate ....................................................................................................................................................... 589
IN Predicate .............................................................................................................................................................. 590
NULL Predicate ......................................................................................................................................................... 592
Chapter 27: Search Conditions 593
Chapter 28: SQL Statements 597
Preliminary Information—Lock Levels ..................................................................................................................... 597
Contents 15
Statements That Support Procedures and Triggers ................................................................................................. 597
ALTER TABLE ............................................................................................................................................................. 598
Description ........................................................................................................................................................ 601
Processing ......................................................................................................................................................... 606
Assignment Statement ............................................................................................................................................. 610
CALL/EXECUTE PROCEDURE ..................................................................................................................................... 610
CASE Statement ........................................................................................................................................................ 612
CLOSE ....................................................................................................................................................................... 612
Description ........................................................................................................................................................ 613
Processing ......................................................................................................................................................... 613
COMMENT ON.......................................................................................................................................................... 613
Description ........................................................................................................................................................ 614
COMMIT WORK ........................................................................................................................................................ 616
Description ........................................................................................................................................................ 616
CREATE INDEX .......................................................................................................................................................... 618
Description ........................................................................................................................................................ 619
Processing ......................................................................................................................................................... 620
CREATE PROCEDURE ................................................................................................................................................ 620
External Procedures .......................................................................................................................................... 622
SQL Procedures ................................................................................................................................................. 622
CREATE PROCEDURE Syntax and Description ................................................................................................... 624
CREATE RULE ............................................................................................................................................................ 676
CREATE SCHEMA ...................................................................................................................................................... 676
Description ........................................................................................................................................................ 677
CREATE SYNONYM ................................................................................................................................................... 678
Description ........................................................................................................................................................ 679
CREATE TABLE .......................................................................................................................................................... 680
Description ........................................................................................................................................................ 681
Privileges ........................................................................................................................................................... 682
Column Definition ............................................................................................................................................. 683
Column Constraint Definition ........................................................................................................................... 684
Table Constraint Definition ............................................................................................................................... 687
Referential Constraint Definition ...................................................................................................................... 689
Data Types ......................................................................................................................................................... 695
CREATE TRIGGER/RULE ............................................................................................................................................ 702
CREATE VIEW ............................................................................................................................................................ 705
Privileges ........................................................................................................................................................... 706
Description ........................................................................................................................................................ 707
Processing ......................................................................................................................................................... 708
DECLARE CURSOR ..................................................................................................................................................... 710
Description ........................................................................................................................................................ 712
Cursor Usage ..................................................................................................................................................... 714
16 SQL User Guide
Example1 ........................................................................................................................................................... 715
Example 2 .......................................................................................................................................................... 716
Example 3 .......................................................................................................................................................... 716
DECLARE STATEMENT .............................................................................................................................................. 717
DELETE ...................................................................................................................................................................... 717
Searched DELETE ............................................................................................................................................... 718
Positioned DELETE ............................................................................................................................................. 718
Description ........................................................................................................................................................ 719
Processing ......................................................................................................................................................... 720
DESCRIBE .................................................................................................................................................................. 721
Description ........................................................................................................................................................ 723
DROP ........................................................................................................................................................................ 725
Description ........................................................................................................................................................ 728
Example 1 .......................................................................................................................................................... 731
Example 2 .......................................................................................................................................................... 731
Example 3 .......................................................................................................................................................... 731
EXECUTE ................................................................................................................................................................... 731
Description ........................................................................................................................................................ 732
Parameter Marker Replacement ...................................................................................................................... 733
EXECUTE IMMEDIATE ............................................................................................................................................... 734
Description ........................................................................................................................................................ 735
Rules for Statement Strings............................................................................................................................... 735
EXECUTE PROCEDURE .............................................................................................................................................. 735
FETCH ....................................................................................................................................................................... 736
Description ........................................................................................................................................................ 738
GRANT ...................................................................................................................................................................... 742
Plan Security ...................................................................................................................................................... 742
Description of Plan Security Diagram ................................................................................................................ 743
Description of Non-Plan Security Diagram ........................................................................................................ 744
IF-THEN Statement ................................................................................................................................................... 746
INSERT ...................................................................................................................................................................... 747
Description ........................................................................................................................................................ 748
Rules for Inserting ............................................................................................................................................. 749
Processing ......................................................................................................................................................... 749
ITERATE Statement ................................................................................................................................................... 750
LEAVE Statement ...................................................................................................................................................... 750
LOCK TABLE .............................................................................................................................................................. 751
Description ........................................................................................................................................................ 751
Example ............................................................................................................................................................. 752
LOOP Statement ....................................................................................................................................................... 752
OPEN ........................................................................................................................................................................ 752
Description ........................................................................................................................................................ 753
Contents 17
Processing ......................................................................................................................................................... 755
Effect of Temporary Tables ............................................................................................................................... 755
Example ............................................................................................................................................................. 755
PREPARE ................................................................................................................................................................... 756
Description ........................................................................................................................................................ 757
Rules for Statement Strings............................................................................................................................... 758
Rules for Parameter Markers ............................................................................................................................ 758
REPEAT-UNTIL Statement......................................................................................................................................... 759
REVOKE ..................................................................................................................................................................... 759
Plan Security ...................................................................................................................................................... 760
Description of Plan Security Diagram ................................................................................................................ 760
Description of Non-Plan Security Diagram ........................................................................................................ 762
Example 1 .......................................................................................................................................................... 763
Example 2 .......................................................................................................................................................... 764
Example 3 .......................................................................................................................................................... 764
ROLLBACK WORK...................................................................................................................................................... 764
Description ........................................................................................................................................................ 765
SELECT ...................................................................................................................................................................... 766
Subselect ........................................................................................................................................................... 767
Full-Select Statement ........................................................................................................................................ 776
Description ........................................................................................................................................................ 776
Select-Statement ............................................................................................................................................... 777
ORDER BY Clause ............................................................................................................................................... 779
Select-Into Statement ....................................................................................................................................... 781
SET CURRENT SQLID ................................................................................................................................................. 787
Description ........................................................................................................................................................ 788
Example ............................................................................................................................................................. 789
UPDATE .................................................................................................................................................................... 789
Searched UPDATE ............................................................................................................................................. 790
Positioned UPDATE ........................................................................................................................................... 790
WHENEVER ............................................................................................................................................................... 794
Description ........................................................................................................................................................ 794
Processing ......................................................................................................................................................... 795
Example ............................................................................................................................................................. 796
WHILE Statement ..................................................................................................................................................... 796
Appendix A: SQL Query Optimization Messages 797
Message Table (SYSADM.SYSMSG) .......................................................................................................................... 797
Requesting Messages ............................................................................................................................................... 798
Bind-time Messages ................................................................................................................................................. 798
Bind-time Summary Messages .......................................................................................................................... 798
18 SQL User Guide
Bind-time Detail Messages ................................................................................................................................ 807
Execution-Time Messages ........................................................................................................................................ 812
Execution-Time Summary Messages................................................................................................................. 813
Execution-Time Detail Messages ...................................................................................................................... 816
Examples .................................................................................................................................................................. 818
Appendix B: Accessibility Features 821
Appendix C: Sample Data Tables 823
CUSTOMERS Table: Sample Data ............................................................................................................................ 824
ORDERS Table: Sample Data.................................................................................................................................... 826
Appendix D: Results of Defining Structures Using SQL Statements 827
CREATE INDEX Statement ........................................................................................................................................ 827
CREATE PROCEDURE Statement............................................................................................................................... 828
CREATE SCHEMA Statement .................................................................................................................................... 829
CREATE TABLE Statement ........................................................................................................................................ 829
CREATE SYNONYM Statement .................................................................................................................................. 837
CREATE TRIGGER Statement .................................................................................................................................... 837
CREATE VIEW Statement .......................................................................................................................................... 839
Appendix E: Results of Using ALTER TABLE 841
Appendix F: SQL Object Consistency Analyzer and Upgrade Rebind Utilities 849
SQL Object Consistency Analyzer ............................................................................................................................. 849
Running the SQL Object Consistency Analyzer ................................................................................................. 850
Correcting Problems ......................................................................................................................................... 856
DBSRFPR (SQL Upgrade Rebind Utility) .................................................................................................................... 861
Rebinding with DBSRFPR ..........................................................
top related