User`s guide

Import Data Using a Scrollable Cursor with a Relative Position Offset
6-65
Import Data Using a Scrollable Cursor with a Relative Position
Offset
This example shows how to use a scrollable cursor to import data using both absolute and
relative position offsets. This example assumes you are connecting to a MySQL database
that contains a table called productTable. This table contains 15 records, where each
record represents one product. The scrollable cursor functionality behaves differently
depending on your database driver. For details about the scrollable cursor functionality
in your database, consult your database documentation.
Connect to the Database
Connect to the MySQL database using the native ODBC interface. This code assumes
you are connecting to a data source named MySQL with user name username and
password pwd.
conn = database.ODBCConnection('MySQL','username','pwd');
Create a Scrollable Cursor
Select all products from the productTable table and sort them in ascending order
by product number. Create a scrollable cursor using the name-value pair argument
'cursorType'.
curs = exec(conn,'select * from productTable order by productNumber',...
'cursorType','scrollable');
Retrieve Data Using an Absolute Position Offset
Import the data for two products in the middle of the data set. Use the row limit 2 to
import data for two products. Use the absolute position offset 5 to import data starting
from the fifth product in the data set.
curs = fetch(curs,2,'absolutePosition',5);
Display the data for the two products.
curs.Data
ans =
[5] [400455] [1005] [3] 'Tin Soldier'
[6] [400876] [1004] [8] 'Sail Boat'