Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

columnnames

Retrieve names of columns in fetched data set

Syntax

columnlist = columnnames(curs)
columnlist = columnnames(curs,returnCellArray)

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.

example

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 a 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)

Create a 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);

Return the column names in the suppliers table as a cell array.

columnlist = columnnames(curs,true)
columnlist =

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

columnlist contains a cell array of the column names in the suppliers table. The cell array has five rows for each column name.

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.

Introduced before R2006a

Was this topic helpful?