IBM DB2 Manual page 149

Table of Contents

Advertisement

Table 21. FETCH clauses for positioning a scrollable cursor (continued)
Method
1,4
RELATIVE(n)
1,5
AFTER
1,5
BEFORE
Notes:
1. This value is not supported for connections to IBM Informix Dynamic Server
2. If the cursor is after the last row of the result table, this method positions the cursor on
the last row.
3. If the absolute value of n is greater than the number of rows in the result table, this
method positions the cursor after the last row if n is positive, or before the first row if n
is negative.
4. Suppose that m is the number of rows in the result table and x is the current row
number in the result table. If n>0 and x+n>m, the iterator is positioned after the last row.
If n<0 and x+n<1, the iterator is positioned before the first row.
5. Values are not assigned to host expressions.
b. If update or delete operations by the iterator or by other means are visible
in the result table, invoke the getWarnings method to check whether the
current row is a hole.
5. Invoke the close method to close the iterator.
The following code demonstrates how to use a named iterator to retrieve the
employee number and last name from all rows from the employee table in reverse
order. The numbers to the right of selected statements correspond to the
previously-described steps.
#sql iterator ScrollIter implements sqlj.runtime.Scrollable
(String EmpNo, String LastName);
{
ScrollIter scrliter;
#sql [ctxt]
scrliter={SELECT EMPNO, LASTNAME FROM EMPLOYEE};
scrliter.afterLast();
while (scrliter.previous())
{
System.out.println(scrliter.EmpNo() + " "
+ scrliter.LastName());
}
scrliter.close();
}
Related concepts
"SQL statement execution in SQLJ applications" on page 112
"Data retrieval in SQLJ applications" on page 123
"Temporary table space storage requirements" (DB2 Installation Guide)
Related tasks
"Using a named iterator in an SQLJ application" on page 124
"Using a positioned iterator in an SQLJ application" on page 126
Related reference
"SQLJ implements-clause" on page 282
"SQLJ with-clause" on page 283
"SQLJ iterator-declaration-clause" on page 285
Positions the cursor
If n>0, on the row that is n rows after the current row.
If n<0, on the row that is n rows before the current
row. If n=0, on the current row.
After the last row in the result table
Before the first row in the result table
Chapter 4. SQLJ application programming
1
2
4a
4c
5
133

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents