cols

(Not recommended) Retrieve number of columns in fetched data set

The cols function is not recommended. There is no replacement for this functionality. To import data, use the fetch function. For details, see Compatibility Considerations.

Description

example

numcols = cols(curs) returns the number of columns in the fetched data set curs.

Examples

collapse all

Create the database connection conn using the dbdemo data source.

conn = database('dbdemo','','');

Working with the dbdemo data source, use fetch to import all data into Database Cursor Object curs. Store the data in a cell array contained in the cursor object field curs.Data.

curs = exec(conn,'SELECT * FROM producttable');
curs = fetch(curs);

View the contents of the Data property in the cursor object.

curs.Data
ans = 

    [ 9]    [125970]    [1003]    [13]    'Victorian Doll' 
    [ 8]    [212569]    [1001]    [ 5]    'Train Set'      
    [ 7]    [389123]    [1007]    [16]    'Engine Kit'     
    [ 2]    [400314]    [1002]    [ 9]    'Painting Set'   
    [ 4]    [400339]    [1008]    [21]    'Space Cruiser'  
    [ 1]    [400345]    [1001]    [14]    'Building Blocks'
    [ 5]    [400455]    [1005]    [ 3]    'Tin Soldier'    
    [ 6]    [400876]    [1004]    [ 8]    'Sail Boat'      
    [ 3]    [400999]    [1009]    [17]    'Slinky'         
    [10]    [888652]    [1006]    [24]    'Teddy Bear'     

Data contains the producttable data.

Display the number of columns in the Data property in the cursor object.

numcols = cols(curs)
numcols =

     5

The data in the cursor object contains five columns.

After you finish working with the cursor object, close it.

close(curs)

Close the database connection.

close(conn)

Input Arguments

collapse all

Database cursor, specified as a cursor object created using the exec function.

Output Arguments

collapse all

Number of columns in a data set, returned as a numeric scalar.

Compatibility Considerations

expand all

Not recommended starting in R2018b

Introduced before R2006a