DB2 Server for VSE & VM SQL Reference
Total Page:16
File Type:pdf, Size:1020Kb
DB2ServerforVSE&VM SQL Reference Version 7 Release 2 SC09-2989-01 DB2ServerforVSE&VM SQL Reference Version 7 Release 2 SC09-2989-01 | Before using this information and the product it supports, be sure to read the general information under “Notices” on page 467. | This document contains proprietary information of IBM. It is provided under a license agreement and is protected | by copyright law. The information contained in this publication does not include any product warranties, and any | statements provided in this manual should not be interpreted as such. | Order publications through your IBM representative or the IBM branch office serving your locality or by calling | 1-800-879-2755 in the United States or 1-800-IBM-4YOU in Canada. | When you send information to IBM, you grant IBM a nonexclusive right to use or distribute the information in any | way it believes appropriate without incurring any obligation to you. © Copyright International Business Machines Corporation 1988, 2001. All rights reserved. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents Summary of Changes ........vii Data Representation Considerations .....29 || Summary of Changes for DB2 Version 7 Release 2 vii Character Conversion ...........29 | Enhancements, New Functions, and New Character Sets and Code Pages .......31 || Capabilities .............vii Coded Character Sets and CCSIDs......31 | Reliability, Availability, and Serviceability Authorization and Privileges ........32 || Improvements............viii Chapter 3. Language Elements ....35 Chapter 1. Introduction ........1 Characters ...............35 Who This Book Is For ...........1 Tokens................36 Prerequisite Knowledge..........1 Spaces...............36 How This Book Is Organized .........1 Comments..............36 Syntax Notation Conventions .........2 Identifiers ...............36 SQL Reserved Words ...........6 SQL Identifiers ............36 Conventions for Representing Mixed Data Values . 6 Host Identifiers ............37 Short Forms Used in Syntax Diagrams......7 Naming Conventions ...........38 Authorization IDs and Authorization-names . 41 Chapter 2. Concepts .........9 Example 1 ..............41 Example 2 ..............41 StaticSQL...............9 Data Types ..............42 Dynamic SQL ..............9 ResultSetLocators...........42 Interactive SQL .............10 Nulls...............43 Extended Dynamic SQL ..........10 Character Strings ...........44 Relational Database............10 Graphic Strings ............47 Tables................10 Numbers..............47 Keys.................11 Datetime Values ............48 PrimaryKeys..............11 NullValues..............51 Integrity ...............11 Assigning Null Values Within the Database: . 51 Data Integrity ............12 Returning Null Values to the Application from Entity Integrity ............12 theDatabase:.............52 Referential Integrity ..........12 Null Values within Expressions and Predicates 52 RelationshipsBetweenTables.......12 Equality and Ordering of Null Values: ....52 ForeignKeys.............13 CheckingforaNullValue:........52 Referential Constraints..........13 AssignmentsandComparisons........53 Delete Rules .............13 Numeric Assignments ..........53 Insert Rules .............16 String Assignments ...........55 Update Rules .............16 Conversion Rules for String Assignments . 56 ActivatingandDeactivatingKeys......17 Datetime Assignments ..........56 Indexes................17 Numeric Comparisons..........57 Views................17 String Comparisons...........58 Packages ...............18 Conversion Rules for String Comparison . 58 Catalog................18 Datetime Comparisons .........59 Application Processes, Concurrency, and Recovery 18 Constants...............59 IsolationLevel.............20 IntegerConstants...........60 RepeatableRead(RR)..........20 Floating-PointConstants.........60 Cursor Stability (CS) ..........21 Decimal Constants ...........60 Uncommitted Read (UR) .........21 Character String Constants ........60 Isolation Level Restrictions ........22 Graphic String Constants .........61 IsolationLevelEscalation.........22 Special Registers.............62 Program Control of Isolation .......22 USER ...............62 Application Requesters and Application Servers . 22 CURRENT DATE ...........62 Distributed Relational Database ......23 CURRENT SERVER ..........62 Application Servers in DRDA .......25 CURRENT TIME ...........63 RemoteUnitofWork..........26 CURRENT TIMESTAMP .........63 Distributed Unit of Work .........26 CURRENT TIMEZONE .........63 The Use of DB2 Family SQL on Various ColumnNames.............63 Application Servers...........26 © Copyright IBM Corp. 1988, 2001 iii Qualified Column Names.........64 Authorization.............121 ReferencestoHostVariables.........68 subselect ...............121 TheMetavariablehost-variable.......68 select-clause .............122 HostStructuresandIndicatorArrays.....69 from-clause..............124 Expressions ..............71 where-clause .............125 Without Operators ...........71 group-by-clause ............125 With the Concatenation Operator ......72 having-clause .............126 With Arithmetic Operators ........73 Examples of a subselect ..........127 Two-Integer Operands ..........73 Example 1 .............127 Integer and Decimal Operands .......73 Example 2 .............127 Two-Decimal Operands .........73 Example 3 .............127 Decimal Arithmetic in SQL ........74 Example 4 .............127 Floating-Point Operands .........74 Example 5 .............127 Datetime Operands ...........74 Example 6 .............127 Datetime Arithmetic in SQL ........75 Example 7 .............128 Precedence of Operations .........78 fullselect ...............128 Predicates...............79 Examples of a fullselect .........129 BasicPredicate............79 Conversion Rules for Operations that Combine Quantified Predicate ..........80 Strings..............130 BETWEEN Predicate ..........81 select-statement ............132 EXISTSPredicate...........83 order-by-clause............132 INPredicate.............84 update-clause ............133 LIKEPredicate............86 with-clause.............134 NULLPredicate.............89 Examples of a select-statement ......134 Search Conditions ............89 Example 1 ..............90 Chapter 6. Statements .......137 Example 2 ..............90 How SQL Statements Are Invoked ......140 Embedding a Statement in an Application Chapter 4. Functions.........91 Program..............141 ColumnFunctions............91 Dynamic Preparation and Execution.....141 AVG................91 Static Invocation of a select-statement ....142 COUNT ..............92 Dynamic Invocation of a select-statement . 142 MAX...............93 Interactive Invocation .........142 MIN................94 SQL Return Codes............143 SUM................95 SQLCODE .............143 ScalarFunctions.............96 SQLSTATE .............143 CHAR...............96 SQLComments.............144 DATE...............98 Example ..............144 DAY................99 ACQUIRE DBSPACE ...........145 DAYS...............100 ALLOCATE CURSOR ..........147 DECIMAL .............101 ALTER DBSPACE ............149 DIGITS..............101 ALTER PROCEDURE...........151 FLOAT ..............102 ALTER PSERVER ............156 HEX...............103 ALTER TABLE .............158 HOUR...............104 ASSOCIATE LOCATORS .........167 INTEGER .............104 BEGIN DECLARE SECTION ........170 LENGTH..............105 CALL ................172 MICROSECOND ...........106 CLOSE ...............176 MINUTE..............106 Extended CLOSE ............178 MONTH..............107 COMMENTON............179 SECOND ..............107 COMMENT ON PROCEDURE .......181 STRIP ...............108 COMMIT...............183 SUBSTR ..............110 CONNECT(forVM)...........186 TIME...............112 CONNECT (for VSE) ...........192 TIMESTAMP............113 CREATE INDEX ............199 TRANSLATE ............115 CREATE PACKAGE ...........202 VALUE ..............117 CREATE PROCEDURE ..........209 VARGRAPHIC ............118 CREATE PSERVER ...........217 YEAR ...............119 CREATE SYNONYM ...........219 CREATE TABLE ............220 Chapter 5. Queries .........121 CREATE VIEW .............232 iv SQL Reference DECLARE CURSOR ...........236 “Roadmap” toCatalog..........370 Extended DECLARE CURSOR .......241 Updateable Columns ...........371 DELETE ...............243 SYSACCESS ..............373 DESCRIBE ..............248 SYSCATALOG .............375 Extended DESCRIBE ...........252 SYSCCSIDS ..............378 DESCRIBE CURSOR ...........253 SYSCHARSETS.............378 DESCRIBE PROCEDURE .........255 SYSCOLAUTH .............379 DROP ................258 SYSCOLSTATS .............380 DROP PROCEDURE ...........261 SYSCOLUMNS .............381 DROP PSERVER ............262 SYSDBSPACES .............384 DROP STATEMENT ...........263 SYSDROP ..............385 END DECLARE SECTION .........264 SYSFIELDS ..............386 EXECUTE ..............265 SYSFPARMS..............387 Extended EXECUTE ...........269 SYSINDEXES .............388 EXECUTE IMMEDIATE ..........271 SYSKEYCOLS .............390 EXPLAIN ..............274 SYSKEYS ...............391 FETCH ...............284 SYSLANGUAGE ............392 Extended FETCH ............288 SYSOPTIONS .............393 GRANT (Package Privileges) ........289 SYSPARMS ..............395 GRANT (System Authorities) ........291 SYSPROGAUTH ............396 GRANT (Table Privileges) .........294 SYSPSERVERS .............397