Converting To Anthony Tichonoff Florida Hospital MIS January 2007 With Ease Multi-Row Fetch.

Slides:



Advertisements
Similar presentations
Definition Cursor is a control structure for the successive traversal of records in a result set. Cursor is a record pointer in a database. DATABASE CURSOR.
Advertisements

AN INTRODUCTION TO PL/SQL Mehdi Azarmi 1. Introduction PL/SQL is Oracle's procedural language extension to SQL, the non-procedural relational database.
PL/SQL. Introduction to PL/SQL PL/SQL is the procedure extension to Oracle SQL. It is used to access an Oracle database from various environments (e.g.
Murali Mani Persistent Stored Modules (Stored Procedures) : PSM.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
Lecture-5 Though SQL is the natural language of the DBA, it suffers from various inherent disadvantages, when used as a conventional programming language.
Chapter 4B: More Advanced PL/SQL Programming
1 Minggu 6, Pertemuan 11 Programmatic SQL Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
Murali Mani SQL with other Programming Languages.
Introduction to Structured Query Language (SQL)
End of SQL: Triggers, Impedance Mismatch and Transactions February 6 th, 2004.
Chapter 7 Advanced SQL Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
A Guide to SQL, Seventh Edition. Objectives Embed SQL commands in PL/SQL programs Retrieve single rows using embedded SQL Update a table using embedded.
Introduction to Structured Query Language (SQL)
Where Do We Start? How Do We Debug? Sources of Debug Information –CICS Transaction Abends –Batch Abend Codes –System Codes –Message Logs –DB2 SQL Codes.
DB2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/DB01/003 Version No:2.0a Session Plan SPUFI Hands On Introduction to Embedded SQL DCLGEN.
Jump-Start Embedded SQL into RPG Presented by: Robert Arce.
Bordoloi and Bock CURSORS. Bordoloi and Bock CURSOR MANIPULATION To process an SQL statement, ORACLE needs to create an area of memory known as the context.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
Agenda Journalling More Embedded SQL. Journalling.
Oracle10g Developer: PL/SQL Programming1 Objectives Manipulating data with cursors Managing errors with exception handlers Addressing exception-handling.
Chapter 4 Cursors and Exception Handling Oracle10g Developer:
Sofia, Bulgaria | 9-10 October SQL Server 2005 High Availability for developers Vladimir Tchalkov Crossroad Ltd. Vladimir Tchalkov Crossroad Ltd.
Dinamic SQL & Cursor. Why Dinamic SQL ? Sometimes there is a need to dynamically create a SQL statement on the fly and then run that command. This can.
Stored Procedures, Transactions, and Error-Handling
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Modification of the Database – Deletion Delete all tuples from the loan relation. delete.
Overview · What is PL/SQL · Advantages of PL/SQL · Basic Structure of a PL/SQL Block · Procedure · Function · Anonymous Block · Types of Block · Declaring.
DB2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/DB01/003 Version No:2.0a Session Plan Introduction to Concurrency Control Different types.
Advanced SQL: Cursors & Stored Procedures
Stored Procedures Week 9. Test Details Stored Procedures SQL can call code written in iSeries High Level Languages –Called stored procedures SQL has.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
ICS 321 Fall 2010 SQL in a Server Environment (i) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 11/1/20101Lipyeow.
Programmatic SQL Shaista Khan CS 157B. Topic Embedded SQL statements in high-level programming languages.
SQL in a Programming Environment CIS 4301 Lecture Notes Lecture /11/2006.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Trigger Oracle PL/SQL. Triggers Associated with a particular table Associated with a particular table Automatically executed when a particular event occurs.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 9 Database Triggers.
1 CS 430 Database Theory Winter 2005 Lecture 14: Additional SQL Topics.
Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Chapter 4: SQL Complex Queries Complex Queries Views Views Modification of the Database Modification of the Database Joined Relations Joined Relations.
Oracle10g Developer: PL/SQL Programming1 Objectives SQL queries within PL/SQL Host or bind variables The %TYPE attribute Include queries and control structures.
1 Pertemuan > > Matakuliah: >/ > Tahun: > Versi: >
Different Constraint Types Type Where Declared When activated Guaranteed to hold? Attribute with attribute on insertion not if CHECK or update subquery.
Chapter 8 Embedded SQL.
Retrieving Data in PL/SQL. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Recognize the SQL statements that can.
Oracle11g: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
implicit and an explicit cursor
In this module, we will design a program to work with the PROJECT table, learning to insert a new project into the table, to delete one or more projects.
Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Function, Trigger used in PosgreSQL.
IMS 4212: Database Implementation 1 Dr. Lawrence West, Management Dept., University of Central Florida Physical Database Implementation—Topics.
1 Stored Procedures in MySQL Part I. 2 Objectives SQL Vs. MySQL SP MySQL SP Parameters MySQL SP Control Structures.
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
DML Statements contd.. SQL Server CURSORS Cursor is used in handling results of select query for data calculations Cursors are used as buffered.
Lu Wei1 Outline Introduction Basic SQL Setting Up and Using PostgreSQL Advanced SQL Embeded SQL.
RETRIEVE A NO. OF ROWS ¦ Declare a cursor ¦ Open the cursor ¦ Fetch rows of data ¦ Stop fetching rows ¦ Close the cursor.
Chapter 8 Advanced SQL Pearson Education © Chapter 8 - Objectives How to use the SQL programming language How to use SQL cursors How to create stored.
1 Section 10 - Embedded SQL u Many computer languages allow you to embed SQL statements within the code (e.g. COBOL, PowerBuilder, C++, PL/SQL, etc.) u.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
SQL Environment.
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Error Handling Summary of the next few pages: Error Handling Cursors.
Chapter 2 Handling Data in PL/SQL Blocks Oracle9i Developer:
Embedded DB2.
Unit I-2.
Chapter 8 Advanced SQL.
Database SQL.
Presentation transcript:

Converting To Anthony Tichonoff Florida Hospital MIS January 2007 With Ease Multi-Row Fetch

Agenda Why use multi-row fetching Why use multi-row fetching What I need to know using multi-row fetching What I need to know using multi-row fetching Extras about multi-row fetching Extras about multi-row fetching How to bridge into multi-row fetching with ease How to bridge into multi-row fetching with ease

Why use multi-row fetching? Converting To Multi-row Fetching With Ease

Why use multi-row fetch Performance Advantages Improves Throughput Improves Throughput Fewer database access calls Lower network operations Lowers CPU consumption Lowers CPU consumption V8 ROU ( Return On Upgrade ) V8 ROU ( Return On Upgrade )

Advantages: Performance Single – Row Fetch Multi – Row Fetch ApplicationDBM1MSTRIRLM ApplicationDBM1MSTRIRLM declare cursor open cursor close cursor commit fetch declare cursor open cursor close cursor commit fetch

CPU Consumption

Return on Upgrade What does V8 cost you? online transaction 0%+15% transaction in data sharing -5%+10% batch -5%+20% insert -5%+5% fetch, select, update +5%+20% batch data sharing -10%+15% batch DRDA -20%+15% utility -5%+10% query -20%+15% Performance objective is less than 10% average regression. Performance objective is less than 10% average regression. Typical customer workload regression is expected to be 5 to 10% higher on average, differing by work load: Typical customer workload regression is expected to be 5 to 10% higher on average, differing by work load: Options with significant potential to offset an expected increase include multi-row fetch, multi-row insert, long term page fix and rebind. Options with significant potential to offset an expected increase include multi-row fetch, multi-row insert, long term page fix and rebind. Return on Upgrade

What you need to know. Converting To Multi-row Fetching With Ease

Requirements for Multi-row Understanding the foundation What is a rowset What is a rowset New SQL syntax New SQL syntaxDeclareFetch Host variable arrays Host variable arrays Error handling Error handling

What is a rowset? A group of rows for the result table of a query that are returned by a single fetch statement. The maximum size of the rowset is The program fetch call controls how many rows are returned in a rowset. It is possible to intertwine single-row and multi-row fetches within the same program. SingleFetch Single Row MultipleFetch Multiple Rows

Declare Syntax Changes DECLARE CURSOR Syntax NO SCROLL DECLARE cursor-name ASENSITIVE INSENSITIVE SENSITIVE STATIC DYNAMIC SCROLL CURSOR FOR Select-Statement select-name rowset-positioning WITH HOLD WITH RETURN WITHOUT ROWSET POSITIONING WITH ROWSET POSITIONING rowset-positioning: Default is WITHOUT ROWSET POSITIONING

Declare Syntax Example SQL Declare with rowset positioning Declare C1 as the cursor of a query to retrieve a rowset from table PayRoll Exec SQL Declare C1 Cursor With Rowset Positioning For Select * From PayRoll Where …. End Exec With Rowset Positioning specifies whether multiple rows of data can be accessed as a rowset on a single Fetch statement

Fetch Syntax Changes FETCH Syntax fetch-orientation: FETCH INSENSITIVE SENSITIVE fetch-orientation FROM cursor-name single-row-fetch multiple-row fetch rowset-positioned BEFORE AFTER row-positioned multiple-row-fetch: rowset-positioned:, NEXT ROWSET PRIOR ROWSET FIRST ROWSET LAST ROWSET CURRENT ROWSET ROWSET STARTING AT ABSOLUTE RELATIVE host-variable integer-constant FOR host-variable integer-constant ROWS INTO INTO DESCRIPTOR host-variable-array descriptor-name

Fetch Syntax Example SQL Fetch with rowset positioning Fetch the next rowset Exec SQL Fetch Next Rowset From C1 For :Rowset-Limit Rows Into :HA_C1 :HA_C1,:HA_C2,:HA_C3 End Exec For :HV Rows is not required. The fetch statement will default to the row limit from the previous fetch statement.

Host variable arrays Fetching into arrays will return multiple rows in a single API call. PayRoll Row 1 MultipleFetch Fetching Multiple Rows Row 2 Row 3 Row 4 HA 1 HA 2 HA 3 HA 4 HA 5 HA 6 Each host variable array can only point to a single DB2 column

EXEC SQL DECLARE TEST.PAYROLL TABLE ( Column_01 CHAR(1) NOT NULL, Column_02 TIMESTAMP NOT NULL, Column_02 TIMESTAMP NOT NULL, Column_03 CHAR(8) NOT NULL, Column_03 CHAR(8) NOT NULL, Column_04 CHAR(1) NOT NULL, Column_04 CHAR(1) NOT NULL, Column_05 CHAR(8) NOT NULL, Column_05 CHAR(8) NOT NULL, ) END-EXEC. 01 DCLHVA. 01 DCLHVA. 05 HVA-Column-01 PIC X(1) OCCURS 100 TIMES. 05 HVA-Column-02 PIC X(26) OCCURS 100 TIMES. 05 HVA-Column-03 PIC X(8) OCCURS 100 TIMES. 05 HVA-Column-04 PIC X(1) OCCURS 100 TIMES. 05 HVA-Column-05 PIC X(8) OCCURS 100 TIMES. Host variable arrays Host variable array declaration

Error handling multi-row fetch Handling multi-row SQL RC SQL RC is the result for the rowset not for the row. SQL RC is the result for the rowset not for the row. Use the Get Diagnostics statement to return each row’s SQL RC Use the Get Diagnostics statement to return each row’s SQL RC EXEC SQL GET DIAGNOSTICS GET DIAGNOSTICS :rows-returned = Row_Count :rows-returned = Row_Count,:err-count = Number,:err-count = NumberEND-EXEC returns statement information EXEC SQL GET DIAGNOSTICS CONDITION :cond GET DIAGNOSTICS CONDITION :cond :sqlcode = DB2_Returned_SQLCode :sqlcode = DB2_Returned_SQLCode,:sqlstate = Returned_SQLState,:sqlstate = Returned_SQLStateEND-EXEC returns condition information

Error handling multi-row fetch Handling multi-row SQL RC (continue) If SQL RC = 0 then all rows within the rowset have a SQL RC = 0. (Get Diagnostics is not necessary) If SQL RC = 0 then all rows within the rowset have a SQL RC = 0. (Get Diagnostics is not necessary) If SQL RC = +100 then the EOT has been found, but rows could possibly exists within the host variable array to process. (Get Diagnostics is not necessary) If SQL RC = +100 then the EOT has been found, but rows could possibly exists within the host variable array to process. (Get Diagnostics is not necessary) Any other RC not equal to 0 or +100 on a rowset we must treat as you have in the past or use Get Diagnostics. Any other RC not equal to 0 or +100 on a rowset we must treat as you have in the past or use Get Diagnostics.

Information from the SQLCA Useful data within the SQLCA after the rowset Fetch. SQLCODE SQLCODE SQLSTATE SQLSTATE SQLERRD(3) contains the actual number of row returned. SQLERRD(3) contains the actual number of row returned. SQLWARN flags are set to represent all warnings accumulated while processing the Fetch. SQLWARN flags are set to represent all warnings accumulated while processing the Fetch.

Extras about multi-row fetching. Converting To Multi-row Fetching With Ease

Helpful Extras Tips Keeping track of your multi-row cursors information SQLCODE- per cursor SQLCODE- per cursor Rows Returned- per cursor Rows Returned- per cursor Current array position- per cursor Current array position- per cursor Max array limits- per table Max array limits- per table Create ways to prevent exceeding your host variable array boundaries

Helpful Extras Tips How big do we make the arrays Appropriate array size your Appropriate array size your online apps batch apps Creating standard host variable array copybooks. Add max limits for the array Add max limits for the array

Helpful Extras Tips Simple error checking for multi-row fetching Fetch Next Rowset From CS1 For :row-limt Rows Into :HVA-1,:HVA-2,:HVA-3 If (SQLCode = 0 Or SQLCode = 100) And SQLERRD(3) > 0 - Process SQLERRD(3) rows Else If SQLCode = 100 and SQLERRD(3) = 0 - Close Cursor Else Handle SQL Error

How to bridge into multi-row fetching with ease. Converting To Multi-row Fetching With Ease

Bridging to Multi-row fetching Steps to discuss Our Plan Our Plan Our Design Our Design Coding Coding Automation Automation Execution Execution

Bridging to Multi-row fetching Our Plan Limit the amount of coding necessary to convert to multi-row fetch. Limit the amount of coding necessary to convert to multi-row fetch. Limit the changes to our error handling. Limit the changes to our error handling. Make the changes fit our current program’s architecture framework. Make the changes fit our current program’s architecture framework. Keep the changes few and simple. Keep the changes few and simple.

Bridging to Multi-row fetching Our Design (Limit the changes) What we have What we have What we want What we want DeclareOpenFetch Loop Until Done Process Work Fetch Next Close Declare Declare (syntax changes)Open Fetch Fetch (syntax changes and wrapper) Loop Until Done Process Work Fetch Next Close Our Goals: - limit change - keep it simple

Bridging to Multi-row fetching Our Design Modifying the Declare with a simple syntax change Modifying the Declare with a simple syntax change Modifying the Fetch… Modifying the Fetch… Fetch SQL Statement (Changes made to acquire multi-row fetch) Add Pre-Fetch Code (Handles decision where to get next row) Add Post-Fetch Code (Handles RCs and array positioning) Add Variable Assignments (Move :HVA elements into :HV)

Coding the Working Storage Table Working Storage Cursor Working Storage

Coding the Prefetch Check array boundaries Get Next Array Row At the end reset SQL return code Fetch next rowset

Coding the Fetch Before After

Coding the Post-Fetch Just executed the fetch Store rows returned & SQL RC per cursor If RC = 0 or (+100 & no array rows) reset array pointer & SQL code

Coding the Data Moves Let eliminate code changes by using our existing host variables.

Bridging to Multi-row fetching Automation The technique, method, or system of operating or controlling a process by highly automatic means, as by electronic devices, reducing human intervention to a minimum. The technique, method, or system of operating or controlling a process by highly automatic means, as by electronic devices, reducing human intervention to a minimum. My definition Lets minimize human error Lets minimize human error Built a Rexx program with ISPF macros to alter existing Cobol code. Built a Rexx program with ISPF macros to alter existing Cobol code.

Multi-Row Fetch Points to remember Use multi-row fetching for a Return on Upgrade Use multi-row fetching for a Return on Upgrade Know the basics for utilizing multi-row fetch Know the basics for utilizing multi-row fetch Extras about multi-row fetching Extras about multi-row fetching Find ways to quickly convert with little code changes to gain back resources. Find ways to quickly convert with little code changes to gain back resources.

Questions? Converting To Multi-row Fetching With Ease Thanks for attending. Anthony Tichonoff Florida Hospital MIS Converting To Multi-Row Fetch With Ease