User`s guide

6 Using Database Toolbox Functions
6-18
Exporting Data to New Record in Database
This example does the following:
1
Retrieves sales data from a salesVolume table.
2
Calculates the sum of sales for 1 month.
3
Stores this data in a cell array.
4
Exports this data to a yearlySales table.
You learn to use the following Database Toolbox functions:
get
fastinsert
setdbprefs
For details about these functions, see matlab\toolbox\database\dbdemos
\dbinsertdemo.m.
1
Connect to the data source, dbtoolboxdemo, if needed:
conn = database('dbtoolboxdemo', '', '');
Alternatively, you can use the native ODBC interface for an ODBC connection. For
details, see database.
2
Use setdbprefs to set the format for retrieved data to numeric:
setdbprefs('DataReturnFormat','numeric')
3
Import ten rows of data the March column of data from the salesVolume table.
curs = exec(conn, 'select March from salesVolume');
curs = fetch(curs);
4
Assign the data to the MATLAB workspace variable AA:
AA = curs.Data
AA =
981
1414
890
1800
2600