columnnames

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

The columnnames 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

columnlist = columnnames(curs) returns the column names of the data selected from a database table in the cursor object curs. The columnnames function is not supported for a cursor object returned by the fetchmulti function.

columnlist = columnnames(curs,returnCellArray) returns the column names as a cell array of character vectors when returnCellArray is set to true.

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.

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

Return the column names in the suppliers table.

columnlist = columnnames(curs)
columnlist =

'SupplierNumber','SupplierName','City','Country','FaxNumber'

columnlist contains one long character vector with the column names in the suppliers table in quotes and separated by commas.

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.

Return format, specified as Boolean values true or false. When set to true, columnnames returns the column names as a cell array of character vectors. When set to false, columnnames returns the column names as a long character vector.

Data Types: logical

Output Arguments

collapse all

Column name list of columns in the selected data, returned as a character vector or a cell array of character vectors. Without the argument returnCellArray, columnnames returns the list of column names as a long character vector. The character vector encloses the column names in quotes and separates the column names by commas. If you use the argument returnCellArray and set it to true, then columnnames returns the column names as a cell array.

Compatibility Considerations

expand all

Not recommended starting in R2018b

See Also

| | | | | |

Introduced before R2006a