19.06.2013 Views

DB2 UDB for z/OS Version 8 Performance Topics - IBM Redbooks

DB2 UDB for z/OS Version 8 Performance Topics - IBM Redbooks

DB2 UDB for z/OS Version 8 Performance Topics - IBM Redbooks

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Characteristics of the host variable array (HVA):<br />

► The HVA is an array in which each element of the array contains a value <strong>for</strong> the same<br />

column (one HVA per column)<br />

► The HVA can only be referenced in multi-row FETCH or INSERT<br />

► The HVA is used to receive multiple values <strong>for</strong> a column on FETCH, or to provide multiple<br />

values <strong>for</strong> a column on INSERT<br />

► The HVA is supported in COBOL, PL/1, C and C++<br />

3.1.1 Example of usage of multi-row fetch in PL/I<br />

Figure 3-2 shows the declaration of Host Variable Arrays, the declaration of the cursor with<br />

rowset positioning, open cursor and fetch of a rowset of 10 rows in a single SQL statement.<br />

Declare HVAs with 10 elements <strong>for</strong> each column<br />

DCL COL1(10) CHAR(8);<br />

Each element of the H<strong>OS</strong>T VARIABLE ARRAY<br />

contains a value <strong>for</strong> the same column<br />

DCL COL2(10) CHAR(8);<br />

DCL COL3(10) BIN FIXED(31);<br />

Declare a CURSOR C1 and fetch 10 rows using a Multi-row FETCH<br />

EXEC SQL<br />

DECLARE C1 CURSOR WITH ROWSET P<strong>OS</strong>ITIONING FOR<br />

SELECT * FROM TABLE1;<br />

WITH ROWSET P<strong>OS</strong>ITIONING specifies<br />

whether multiple rows of data can be accessed<br />

EXEC SQL OPEN C1;<br />

as a rowset on a single FETCH statement<br />

EXEC SQL<br />

FETCH NEXT ROWSET FROM C1 FOR 10 ROWS<br />

INTO :COL1, :COL2, :COL3; The size of the rowset is not specified on the<br />

DECLARE CURSOR statement, it is done at<br />

.....<br />

FETCH time<br />

Figure 3-2 Usage of multi-row fetch<br />

3.1.2 Example of usage of multi-row insert in PL/I<br />

Example 3-1 shows the statement to insert a rowset of 10 rows into a table with a single SQL<br />

statement.<br />

Example 3-1 Insert 10 rows using host variable arrays <strong>for</strong> column values<br />

EXEC SQL<br />

INSERT INTO TABLE2<br />

VALUES ( :COL1, :COL2, :COL3)<br />

FOR 10 ROWS ;<br />

.....<br />

When we increase the number of rows processed per multi-row fetch or insert, the size of the<br />

host variable array is increased in the application program and it is processed row by row in<br />

<strong>DB2</strong>.<br />

32 <strong>DB2</strong> <strong>UDB</strong> <strong>for</strong> z/<strong>OS</strong> <strong>Version</strong> 8 Per<strong>for</strong>mance <strong>Topics</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!