| Contents | Index |
results = fetch(conn, sqlquery)
results = fetch(conn, sqlquery, RowInc)
results = fetch(conn, sqlquery) executes the SQL statement sqlquery, imports data for the open connection object conn, and returns the data to results. (For more information on SQL statements, see exec.)
results = fetch(conn, sqlquery, RowInc) imports RowInc rows of data at a time.
results |
A cell array, structure, or numeric matrix, depending on specifications set by setdbprefs. |
As shown in the syntax section above, you call the database.fetch function with the command fetch rather than database.fetch. You implicitly call database.fetch by passing a database object, conn, to the function fetch. Fetch also works with a cursor object. See cursor.fetch.
The order of records in your database does not remain constant. Use the SQL ORDER BY command in your sqlquery statement to sort data.
This example shows how to import data. (If you experience speed and memory issues, use the rowinc argument
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 1Import two columns of data and view information about the data.
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 2View the results for the first row of data.
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

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |