| Database Toolbox | ![]() |
Import data into MATLAB cell array
Syntax
curs = fetch(curs, RowLimit) curs = fetch(curs) curs.Data
Description
curs = fetch(curs, RowLimit)
imports rows of data from the open SQL cursor curs, up to the specified RowLimit, into the object curs. It is common practice to reassign the variable curs from the open SQL cursor to the object returned by fetch. The next time you run fetch, records are imported starting with the row following RowLimit.
curs = fetch(curs)
imports rows of data from the open SQL cursor curs, up to the RowLimit specified by set, into the object curs. It is common practice to reassign the variable curs from the open SQL cursor to the object returned by fetch. The next time you run fetch, records are imported starting with the row following RowLimit. If no RowLimit was specified by set, fetch imports all remaining rows of data.
Running fetch returns information about the cursor object. The Data element of the cursor object points to the cell array that contains the data returned by fetch. The data types are preserved (cell arrays support mixed data types). After running fetch, display the returned data by typing curs.Data.
Use get to view properties of curs.
Example 1 - Import All Rows of Data
Import all of the data into the cursor object curs.
curs = fetch(curs)
curs =
Attributes: []
Data: {91x1 cell}
DatabaseObject: [1x1 database]
RowLimit: 0
SQLQuery: 'select country from customers'
Message: []
Type: 'Database Cursor Object'
ResultSet: [1x1 sun.jdbc.odbc.JdbcOdbcResultSet]
Cursor: [1x1 com.mathworks.toolbox.database.sqlExec]
Statement: [1x1 sun.jdbc.odbc.JdbcOdbcStatement]
Fetch: [1x1
com.mathworks.toolbox.database.fetchTheData]
The fetch operation stores the data in a cell array pointed to by the element curs.Data of the cursor object. To display data in the cell array curs.Data, type
curs.Data
MATLAB returns all of the data, which in this example consists of 1 column and 91 rows, some of which are shown here.
ans =
'Germany'
'Mexico'
'Mexico'
'UK'
'Sweden'
...
'USA'
'Finland'
'Poland'
Example 2 - Import Specified Number of Rows of Data
Specify the RowLimit argument to retrieve the first 3 rows of data.
curs = fetch(curs, 3)
curs =
Attributes: []
Data: {3x1 cell}
DatabaseObject: [1x1 database]
RowLimit: 0
SQLQuery: 'select country from customers'
Message: []
Type: 'Database Cursor Object'
ResultSet: [1x1 sun.jdbc.odbc.JdbcOdbcResultSet]
Cursor: [1x1 com.mathworks.toolbox.database.sqlExec]
Statement: [1x1 sun.jdbc.odbc.JdbcOdbcStatement]
Fetch: [1x1
com.mathworks.toolbox.database.fetchTheData]
curs.Data
ans =
'Germany'
'Mexico'
'Mexico'
Entering the fetch function again returns the second 3 rows of data. Adding the semicolon suppresses display of the results.
curs = fetch(curs, 3);
curs.Data
ans =
'UK'
'Sweden'
'Germany'
See Also
attr, cols, columnnames, exec, get, rows, resultset, set, width
| exportedkeys | get | ![]() |