Scrollable cursors
How scrollable cursors can be supported on different databases.
DEFINE cust_rec RECORD LIKE customer.*
DECLARE sc SCROLL CURSOR
FOR SELECT * FROM customer
OPEN sc
FETCH NEXT sc INTO cust_rec.*
FETCH LAST sc INTO cust_rec.*
FETCH FIRST sc INTO cust_rec.*
CLOSE sc
This is a useful feature to implement record set navigation in applications. Scrollable cursors are typically implemented in the database server. But not all database servers support scrollable cursors.
When scrollable cursors are not supported by the target database server, the database driver will emulate it with temporary files.
The temporary files are create in a temporary directory, that can be defined with the DBTEMP environment variable. If DBTEMP is not defined, the default temporary directory dependents from the platform used.
It is recommended that you avoid scroll cursor usage if the target database does not support this feature:
With emulated scrollable cursors, when scrolling to the last row, all rows will be fetched into the temporary file. This can generate a lot of network traffic and can produce a large temporary file if the result-set contains a lot of rows. Additionally, programs are dependent on the file system resource allocated to the OS user (ulimit).
The following table lists the native scroll cursor availability for each supported database:
Database Server Type | Scroll cursors support |
---|---|
IBM® DB2® LUW | Yes, see details |
IBM Informix® | Yes, native SQL feature |
IBM Netezza | Emulated, see details |
Microsoft™ SQL Server | Yes, see details |
Oracle® MySQL | Emulated, see details |
Oracle Database Server | Yes, see details |
PostgreSQL | Yes, see details |
SAP HANA® | Emulated, see details |
SQLite | Emulated, see details |