Database Toolbox | ![]() ![]() |
Viewing Information About the Imported Data
In this part of the tutorial, you view information about the data you imported and close the connection. You use these Database Toolbox functions:
If you want to see or copy the functions for this part of the tutorial, or if you want to run the set of functions, use the M-file matlab\toolbox\database\dbdemos\dbinfodemo.m
.
conn = database('SampleDB', '', ''); curs = exec(conn, 'select country from customers'); curs = fetch(curs, 10);
numrows = rows(curs)
colnames = 'country'
columnnames
returns the names of the columns in the data set. In this example, there is only one column, and therefore only one column name, 'country'
, is returned.
colsize = 15
width
returns the column width for the column number you specify. Here, the width of column 1 is 15.
attributes = attr(curs)
attributes = fieldName: 'country' typeName: 'VARCHAR' typeValue: 12 columnWidth: 15 precision: [] scale: [] currency: 'false' readOnly: 'false' nullable: 'true' Message: []
Note that if you had imported multiple columns, you could include a colnum
argument to specify the number of the column for which you want the information.
Always close a cursor when you are finished with it to avoid using memory unnecessarily and to ensure there are enough available cursors for other users.
close(conn)
![]() | Importing Data into MATLAB from a Database | Exporting Data from MATLAB to a New Record in a Database | ![]() |