Main Content

attr

(To be removed) Retrieve attributes of columns in fetched data set

The attr function will be removed in a future release. There is no replacement for this functionality. To import data, use the fetch function. For details, see Compatibility Considerations.

Description

example

attributes = attr(curs) retrieves attribute information for all columns in the fetched data set curs.

attributes = attr(curs,colnum) retrieves attribute information for the column number colnum in the fetched data set curs.

Examples

collapse all

Create the database connection conn to an Oracle® database using an ODBC connection. This code assumes that you are connecting a data source named dbname with user name username and password pwd. The data source identifies an Oracle database that contains the table inventoryTable with these columns: productNumber, Quantity, Price, and inventoryDate.

conn = database(dbname,username,pwd);

Import all the data from the table inventoryTable. The cursor object curs contains the executed query. Import the data from the executed query using the fetch function.

sqlquery = 'SELECT * FROM inventoryTable';

curs = exec(conn,sqlquery);
curs = fetch(curs);

Retrieve attribute information for all the fetched data using curs.

attributes = attr(curs)
attributes = 

1x4 struct array with fields:

    fieldName
    typeName
    typeValue
    columnWidth
    precision
    scale
    currency
    readOnly
    nullable
    Message

attributes contains a structure array for three columns in the table inventoryTable.

Display the attribute data for the first column in the table inventoryTable.

attributes(1)
ans = 

      fieldName: 'PRODUCTNUMBER'
       typeName: 'NUMBER'
      typeValue: 2.00
    columnWidth: 39.00
      precision: 38.00
          scale: 0
       currency: 'true'
       readOnly: 'false'
       nullable: 'true'
        Message: []

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

close(curs)
close(conn)

Input Arguments

collapse all

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

Column number, specified as a numeric scalar to denote the column in the fetched data set curs for retrieving attribute information.

Data Types: double

Output Arguments

collapse all

Attribute data, returned as a structure array containing attribute information for each column in the fetch data set curs. The following attributes are available.

AttributeDescription
fieldName

Name of the column.

typeName

Data type.

typeValue

Numerical representation of the data type.

columnWidth

Size of the field.

precision

Precision value for floating and double data types; an empty value is returned for character vectors or string scalars.

scale

Precision value for real and numeric data types; an empty value is returned for character vectors or string scalars.

currency

If this attribute equals true, the data format is currency.

readOnly

If this attribute equals true, the data cannot be overwritten.

nullable

If this attribute equals true, the data can be NULL.

Message

Error message returned by fetch.

Compatibility Considerations

expand all

Warns starting in R2021a

Introduced before R2006a