Documentation

attr

Retrieve attributes of columns in fetched data set

Syntax

Description

example

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

example

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

Examples

collapse all

Retrieve Attribute Data for a Fetched Data Set

Connect 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);

Fetch all the data from the table inventoryTable into a fetched data set curs.

curs = exec(conn,'select * from inventoryTable');
curs = fetch(curs);

Retrieve attribute information for all the fetched data 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: []

Close the cursor and connection.

close(curs)
close(conn)

Retrieve Attribute Data for a Specific Column

Connect 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);

Fetch all the data from the table inventoryTable into a fetched data set curs.

curs = exec(conn,'select * from inventoryTable');
curs = fetch(curs);

Retrieve attribute information for the third column in the table inventoryTable in the fetched data curs.

attributes = attr(curs,3)
attributes = 

      fieldName: 'PRICE'
       typeName: 'NUMBER'
      typeValue: 2.00
    columnWidth: 39.00
      precision: 126.00
          scale: -127.00
       currency: 'true'
       readOnly: 'false'
       nullable: 'true'
        Message: []

attributes contains a structure with the attribute data for the third column PRICE in the table inventoryTable.

Close the cursor and connection.

close(curs)
close(conn)

Input Arguments

collapse all

curs — Database cursordatabase cursor object

Database cursor, specified as an open SQL database cursor object created using exec.

colnum — Column numberscalar

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

Data Types: double

Output Arguments

collapse all

attributes — Attribute datastructure array

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 strings.

scale

Precision value for real and numeric data types; an empty value is returned for strings.

currency

If this equals true, the data format is currency.

readOnly

If this equals true, the data cannot be overwritten.

nullable

If this equals true, the data can be NULL.

Message

Error message returned by fetch.

Was this topic helpful?