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.

attr

Retrieve attributes of columns in fetched data set

Syntax

attributes = attr(curs)
attributes = attr(curs,colnum)

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

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

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

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

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

Retrieve attribute information for the third column in the table inventoryTable using 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.

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

Introduced before R2006a

Was this topic helpful?