| Database Toolbox™ | ![]() |
results = fetch(conn, sqlquery)
results = fetch(conn, sqlquery,
RowInc)
results = fetch(conn, sqlquery) executes the SQL statement sqlquery and imports data for the open connection object conn.results is a cell array, structure, or numeric matrix, based on specifications set by setdbprefs.
results = fetch(conn, sqlquery, RowInc) executes the SQL statement sqlquery and imports RowInc rows of data at a time, given the open connection object conn. Data is stored in a MATLAB cell array, structure, or numeric matrix, based on specifications set by setdbprefs.
RowInc, manages speed and memory issues. It is a good practice to use RowInc when importing large amounts of data.
For more information on SQL statements, see exec.
This page documents fetch for a database object. For more information about the relationship with cursor.fetch, see fetch.
The order of records in your database does not remain constant. Use the values in column names to identify records. Use the SQL ORDER BY command in your sqlquery statement to sort data.
Import the country column from the customers table in the SampleDB database.
conn= database('SampleDB','','');
setdbprefs('DataReturnFormat','cellarray')
results=fetch(conn, 'select country from customers')results =
'Germany'
'Mexico'
'Mexico'
'UK'
'Sweden'
...
'Finland'
'Brazil'
'USA'
'Finland'
'Poland'View the size of the cell array into which the results were returned.
size(results)ans =
91 1Tip Try running this example using the rowinc argument to address memory and speed issues. |
Import the ProductName and Discontinued columns from the SampleDB database.
conn = database('SampleDB', '', '');
setdbprefs('DataReturnFormat','cellarray')
results=fetch(conn, 'select ProductName, Discontinued from Products');View the size of the cell array into which the results were returned.
size(results)
ans =
77 2To see the results for the first row of data, run:
results(1,:)
ans =
'Chai' [0]View the data type of the second element in the first row of data.
class(results{1,2})
ans =
logicalcursor.fetch, database, exec, fetch, logical,
Retrieving BINARY or OTHER Sun™ Java™ SQL Data Types
![]() | database | dmd | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |