Describes a schema object. This method returns an instance of the OraMetaData
interface.
The arguments for the method are:
Arguments | Description |
---|---|
[in ] SchemaObjectName |
A String representing the name of the schema object to be described. |
The following schema object types can be described:
Tables
Views
Procedures
Functions
Packages
Sequences
Collections
(VARRAY
s or nested tables)
Types
Describing any other schema object (for example, a column) or an invalid schema object name raises an error. You should navigate to schema objects not listed here, rather than describing them directly.
This method takes the name of a schema object, such as emp
, and returns a COM Automation object (OraMetaData
). The OraMetaData
object provides methods for dynamically navigating and accessing all the attributes (OraMDAttribute
collection) of a schema object described.
The following Visual Basic code illustrates a how to use the Describe
method to retrieve and display several attributes of the emp
table.
Set emp = OraDatabase.Describe("emp") 'Display the name of the Tablespace MsgBox emp!tablespace 'Display name and data type of each column in the emp table. Set empColumns = emp!ColumnList Set ColumnList = empColumns.Value for i = 0 to ColumnList.Count - 1 Set Column = ColumnList(i).Value MsgBox "Column: " & Column!Name & " Data Type: " & Column!Data Type Next i
Before running the following example, make sure that you have the necessary datatypes and tables in the database. See "Schema Objects Used in OraMetaData Examples".
Dim OraSession As OraSession Dim OraDatabase As OraDatabase Dim OraDynaset As OraDynaset Dim OraMetaData As OraMetaData Dim OraMDAttribute As OraMDAttribute Dim ColumnList As OraMetaData Dim Column As OraMetaData 'Create the OraSession Object. Set OraSession = CreateObject("OracleInProcServer.XOraSession") 'Create the OraDatabase Object by opening a connection to Oracle. Set OraDatabase = OraSession.OpenDatabase("ExampleDB", "scott/tiger", 0&) 'Use Describe to retrieve the metadata object Set OraMetaData = OraDatabase.Describe("EMP") 'Display the type of the metadata MsgBox TypeofMetaData & OraMetaData.Type 'Display the count of attributes belonging to the table MsgBox NumberOfAttributes & OraMetaData.Count 'Attribute can be accessed using the explicit OraMetaData property: Attribute 'The index can be an integer or the attribute name Set OraMDAttribute = OraMetaData.Attribute(0) MsgBox "ObjectID: " & OraMDAttribute.Value 'Since Attribute is the default property of OraMetaData, an attribute can ' be accessed as follows. Here, we use attribute name as an index Set OraMDAttribute = OraMetaData("ObjectID") MsgBox "Name: " & OraMDAttribute.Name MsgBox "Value: " & OraMDAttribute.Value 'Value is the default property of OraMDAttribute, the following shows 'the Value of property "IsClustered" for the table MsgBox "Is Clustered: " & OraMetaData!IsClustered MsgBox "Is Partitioned: " & OraMetaData!IsPartitioned 'Retrieve the Column List Set OraMDAttribute = OraMetaData!ColumnList ' Use IsMDObject property to check whether an attribute's value is an OraMetaData If (OraMDAttribute.IsMDObject()) Then Set ColumnList = OraMDAttribute.Value 'Display the name and data type of each column For I = 0 To ColumnList.Count - 1 Set Column = ColumnList(I).Value ' Each column is again an OraMetaData MsgBox "Column: " & Column!Name & " data type: " & Column!Data Type Next I End If
Example: Describing a User-Defined Type
Before running the following example, make sure that you have the necessary datatypes and tables in the database. See "Schema Objects Used in OraMetaData Examples".
Dim OraSession As OraSession Dim OraDatabase As OraDatabase Dim OraDynaset As OraDynaset Dim OraMetaData As OraMetaData Dim OraMDAttribute As OraMDAttribute Dim attrList As OraMetaData Dim attr As OraMetaData 'Create the OraSession Object. Set OraSession = CreateObject("OracleInProcServer.XOraSession") 'Create the OraDatabase Object by opening a connection to Oracle. Set OraDatabase = OraSession.OpenDatabase("ExampleDB", "scott/tiger",0&) Set OraMetaData = OraDatabase.Describe("ORAMD_ADDRESS") NumAttributes = OraMetaData!NumAttributes NumMethods = OraMetaData!NumMethods MsgBox "The Address type has " & NumAttributes & " attributes" MsgBox "Address Object has " & NumMethods & " methods" 'Retrieve the attribute list of this type object Set attrList = OraMetaData!Attributes.Value 'Display the name and data type of each attribute For I = 0 To attrList.Count - 1 Set attr = attrList(I).Value ' each attr is actually an OraMetaData MsgBox "Attribute Name: " & attr!Name MsgBox "Attribute Type: " & attr!TypeName Next I
Example: Describing Unknown Schema Objects
Before running the following example, make sure that you have the necessary datatypes and tables in the database. See "Schema Objects Used in OraMetaData Examples".
Sub RecursiveDescribe(name$, xMD As OraMetaData) Dim xMDAttr As OraMDAttribute For I = 0 To xMD.Count - 1 Set xMDAttr = xMD.Attribute(I) ' If an attribute can be described further, describe it, ' otherwise display its attribute name & value If (xMDAttr.IsMDObject) Then RecursiveDescribe xMDAttr.name, xMDAttr.Value Else MsgBox name & "->" & xMDAttr.name & " = " & xMDAttr.Value End If Next I End Sub Sub Main() 'This example displays all the attributes of any schema object given Dim OraSession As OraSession Dim OraDatabase As OraDatabase Dim OraDynaset As OraDynaset Dim xMD As OraMetaData Dim x As String 'Create the OraSession Object. Set OraSession = CreateObject("OracleInProcServer.XOraSession") 'Create the OraDatabase Object by opening a connection to Oracle. Set OraDatabase = OraSession.OpenDatabase("ExampleDB", "scott/tiger", 0&) ' x is any database object, here the EMP table is used as an example x = "EMP" Set xMD = OraDatabase.Describe(x) MsgBox x & " is of the type " & xMD.Type RecursiveDescribe x, xMD End Sub
See Also: