attr
(Removed) Retrieve attributes of columns in fetched data set
The attr
function has been removed. There is no replacement for this
functionality. To import data, use the fetch
function. For details, see Compatibility Considerations.
Description
retrieves attribute information for all columns in the fetched data set
attributes
= attr(curs
)curs
.
retrieves attribute information for the column number attributes
= attr(curs
,colnum
)colnum
in the
fetched data set curs
.
Examples
Retrieve Attribute Data for a Fetched Data Set
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
colnum
— Column number
numeric scalar
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
attributes
— Attribute data
structure 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.
Attribute | Description |
---|---|
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 |
readOnly | If this attribute equals |
nullable | If this attribute equals |
Message | Error message returned by
|
Version History
Introduced before R2006aR2022a: attr
function has been removed
Errors starting in R2022a
The attr
function has been removed. Use the fetch
function to import data. Some differences between the workflows might
require updates to your code.
Use the fetch
function with the connection
object to import data from a database in one step.
In prior releases, you wrote multiple lines of code to create the cursor
object, import data, and find the attributes of the database columns.
For example:
curs = exec(conn,sqlquery); curs = fetch(curs); results = curs.Data; attributes = attr(curs); close(curs)
Now you can import data in one step using the fetch
function.
results = fetch(conn,sqlquery);
If you return imported data as a table, access details about the variables in the
table by using a function such as summary
.
There is no replacement functionality for the attr
function.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)