Products & Services Solutions Academia Support User Community Company

Learn more about Database Toolbox   

Viewing Information About Imported Data

This example shows how to view information about imported data and close the connection to the database using the following Database Toolbox functions:

For more information on these functions, see matlab\toolbox\database\dbdemos\dbinfodemo.m.

  1. Open the cursor and connection if needed:

    conn = database('SampleDB', '', '');
    curs = exec(conn, 'select country from customers');
    setdbprefs('DataReturnFormat','cellarray');
    curs = fetch(curs, 10);
    
  2. Use rows to return the number of rows in the data set:

    numrows = rows(curs)
    numrows =
        10
    
  3. Use cols to return the number of columns in the data set:

    numcols = cols(curs)
    numcols =
         1
    
  4. Use columnnames to return the names of the columns in the data set:

    colnames = columnnames(curs)
    colnames =
    	'country'
    
  5. Use width to return the column width, or size of the field, for the specified column number:

    colsize = width(curs, 1)
    colsize =
        15
    
  6. Use attr to view multiple attributes for a column:

    attributes = attr(curs)
    attributes = 
          fieldName: 'country'
           typeName: 'VARCHAR'
          typeValue: 12
        columnWidth: 15
          precision: []
              scale: []
           currency: 'false'
           readOnly: 'false'
           nullable: 'true'
            Message: []
    

      Tip   To import multiple columns, include a colnum argument in attr to specify the number of columns whose information you want.

  7. Close the cursor.

    close(curs)
    
  8. Continue with the next example. To stop working now and resume working on the next example at a later time, close the connection.

    close(conn)
    

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS