EasyManuals Logo

IBM DB2 User Manual

IBM DB2
585 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #149 background imageLoading...
Page #149 background image
Table 21. FETCH clauses for positioning a scrollable cursor (continued)
Method Positions the cursor
RELATIVE(n)
1,4
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
1,5
After the last row in the result table
BEFORE
1,5
Before the first row in the result table
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 1
(String EmpNo, String LastName);
{
ScrollIter scrliter; 2
#sql [ctxt]
scrliter={SELECT EMPNO, LASTNAME FROM EMPLOYEE};
scrliter.afterLast();
while (scrliter.previous()) 4a
{
System.out.println(scrliter.EmpNo()+"" 4c
+ scrliter.LastName());
}
scrliter.close(); 5
}
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
Chapter 4. SQLJ application programming 133

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the IBM DB2 and is the answer not in the manual?

IBM DB2 Specifications

General IconGeneral
DeveloperIBM
Initial Release1983
LicenseProprietary
Written inC, C++
CategoryDatabase Management System (RDBMS)
Operating SystemLinux, Windows
Programming LanguagesC, C++
Data ModelsRelational
EditionsCommunity, Standard, Advanced
Key Featureshigh availability, scalability