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

expand all

Retrieve Attribute Data for a Fetched Data Set

Using an ODBC connection to an Oracle® database, retrieve all attribute data for a fetched data set.

Create an Oracle connection. For example, the following code assumes you are connecting a data source named dbname with user name username and password pwd.

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 = 

1x3 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: 'DECIMAL'
      typeValue: 3.00
    columnWidth: 40.00
      precision: 38.00
          scale: []
       currency: 'false'
       readOnly: 'false'
       nullable: 'true'
        Message: []

Close the cursor and connection.

close(curs)
close(conn)

Retrieve Attribute Data for a Specific Column

Using an ODBC connection to an Oracle database, retrieve the attribute data for a specific column in the fetched data set.

Create an Oracle connection. For example, the following code assumes you are connecting a data source named dbname with user name username and password pwd.

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 = 

b = 

      fieldName: 'PRICE'
       typeName: 'NUMBER'
      typeValue: 6.00
    columnWidth: 40.00
      precision: 38.00
          scale: []
       currency: 'false'
       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

expand 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

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

See Also

| | | | | | |

Was this topic helpful?