備考
次のタイプのスキーマ・オブジェクトを記述できます。
表
ビュー
プロシージャ
ファンクション
パッケージ
順序
コレクション(VARRAY
またはネストした表)
型
その他のスキーマ・オブジェクト(列など)または無効なスキーマ・オブジェクト名を記述しようとすると、エラーになります。ここにリストされていないスキーマ・オブジェクトは、直接記述せずにナビゲートしてください。
このメソッドは、emp
などのスキーマ・オブジェクトの名前に基づいて、COMオートメーション・オブジェクト(OraMetaData
)を戻します。OraMetaData
オブジェクトは、記述されているスキーマ・オブジェクトのすべての属性(OraMDAttribute
コレクション)に動的にナビゲートおよびアクセスするメソッドを提供します。
例
Describeの簡単な例
次のVisual Basicコードでは、Describe
メソッドを使用して、emp
表の各種属性を取り出し、表示する方法を示します。
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
表の記述例
次の例を実行する前に、必要なデータ型と表がデータベース内にあることを確認してください。「OraMetaDataの例で使用されているスキーマ・オブジェクト」を参照してください。
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
例: ユーザー定義型の記述
次の例を実行する前に、必要なデータ型と表がデータベース内にあることを確認してください。「OraMetaDataの例で使用されているスキーマ・オブジェクト」を参照してください。
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
例: 不明なスキーマ・オブジェクトの記述
次の例を実行する前に、必要なデータ型と表がデータベース内にあることを確認してください。「OraMetaDataの例で使用されているスキーマ・オブジェクト」を参照してください。
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