Front cover SQL Procedures, Triggers, and Functions on IBM DB2 for i Jim Bainbridge Hernando Bedoya Rob Bestgen Mike Cain Dan Cruikshank Jim Denton Doug Mack Tom Mckinley Simona Pacchiarini Redbooks International Technical Support Organization SQL Procedures, Triggers, and Functions on IBM DB2 for i April 2016 SG24-8326-00 Note: Before using this information and the product it supports, read the information in “Notices” on page ix. First Edition (April 2016) This edition applies to Version 7, Release 2, of IBM i (product number 5770-SS1). © Copyright International Business Machines Corporation 2016. All rights reserved. Note to U.S. Government Users Restricted Rights -- Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents Notices . ix Trademarks . .x IBM Redbooks promotions . xi Preface . xiii Authors. xiii Now you can become a published author, too! . xvi Comments welcome. xvi Stay connected to IBM Redbooks . xvi Chapter 1. Introduction to data-centric programming. 1 1.1 Data-centric programming. 2 1.2 Database engineering . 2 Chapter 2. Introduction to SQL Persistent Stored Module . 5 2.1 Introduction . 6 2.2 System requirements and planning. 6 2.3 Structure of an SQL PSM program . 7 2.4 SQL control statements. 8 2.4.1 Assignment statement . 8 2.4.2 Conditional control . 11 2.4.3 Iterative control . 15 2.4.4 Calling procedures . 18 2.4.5 Compound SQL statement . 19 2.5 Dynamic SQL in PSM . 22 2.5.1 DECLARE CURSOR, PREPARE, and OPEN . 23 2.5.2 PREPARE then EXECUTE. 26 2.5.3 EXECUTE IMMEDIATE statement . 28 2.6 Error handling . 29 2.6.1 The basic database error indicators . 30 2.6.2 Conditions and handlers . 31 2.6.3 GET DIAGNOSTICS. 33 2.6.4 SIGNAL and RESIGNAL. 35 2.6.5 RETURN statement . 37 2.6.6 Direct SQLSTATE and SQLCODE usage. 38 2.6.7 Error handling in nested compound statements . 39 2.7 Transaction management in procedures. 40 2.7.1 Transaction management example. 43 Chapter 3. SQL fundamentals . 47 3.1 SQL concepts . 48 3.1.1 Schemas and libraries . 48 3.1.2 Unqualified object names . 48 3.1.3 SQL PATH . 51 3.1.4 Global variables . 52 3.2 Common information for SQL routines and triggers . 55 3.2.1 Routine and trigger creation process . 55 3.2.2 IBM i names for generated SQL objects . 56 © Copyright IBM Corp. 2016. All rights reserved. iii 3.2.3 CREATE OR REPLACE . 56 3.2.4 Shared attributes. 57 3.3 DB2 sample database. 64 3.4 Transactions . 64 3.4.1 Transaction terminology . 65 3.4.2 Transaction management . 65 3.4.3 Transaction management in compound statements . 68 3.5 DB2 for i catalog views . 70 Chapter 4. Procedures . 73 4.1 Introduction to procedures . 74 4.2 Structure of a procedure . 74 4.3 Creating a procedure . 75 4.3.1 CREATE PROCEDURE syntax . 75 4.4 System catalog tables for procedures. 87 4.4.1 SYSROUTINES catalog . 87 4.4.2 SYSPARMS catalog . 88 4.5 Procedure signature and procedure overloading . 89 4.6 Calling a procedure . 89 4.6.1 CALL statement syntax. 90 4.7 Producing and consuming result sets . 91 4.7.1 Creating result sets in an SQL procedure. 92 4.7.2 Retrieving result sets in the caller . 93 4.8 Handling errors . 98 4.8.1 Basic database error indicators. 98 4.8.2 Handling errors within procedures . 100 4.8.3 Tailoring error messages . 104 4.9 Summary. ..
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages338 Page
-
File Size-