Oracle® Objects for OLE Developer's Guide 11g Release 2 (11.2) for Microsoft Windows Part Number E17727-03 |
|
|
PDF · Mobi · ePub |
The OraObject
interface is a representation of an Oracle value instance (non-referenceable object instance or embedded objects). Value instances are instances of an Oracle object type stored in the column of a table or attribute of an another Oracle object instance or element of an Oracle collection.
Implicitly an OraObject
object contains a collection interface for accessing and manipulating (updating and inserting) individual attributes of an value instance. Individual attributes can be accessed by using a subscript or the name of the attribute.
The OraObject
attribute index starts at 1
. The Count
property returns the total number of attributes. Each attribute of the underlying value instance is represented as an OraAttribute
object.
Attribute values are retrieved as variants. The Variant
type of the attribute depends on the attribute type of the object. Attribute values can be null and can be set to Null
. For object types REF
, LOB, and collection, attribute values are returned as corresponding OO4O objects for that type.
The CreateOraObject
method on the OraDatabase
object returns the OraObject
object. The value instance associated with this OraObject
object is created in the client-side object cache.
For information about executing a member method of a value instance, see "Executing a Member Method of an Oracle Object Instance".
For information about initializing an OraObject
object representing a value instance in OO4O or executing a member method of a value instance, see "Instantiating Oracle LOBs, Objects, and Collections".
See "Schema Objects Used in the OraObject and OraRef Examples" for schema descriptions used in examples of OraObject
/OraRef
objects.
Example: Accessing Attributes of an OraObject Object
The following example accesses the attributes of the ADDRESS
value instance in the database.
Dim OraSession as OraSession Dim OraDatabase as OraDatabase Dim OraDynaset as OraDynaset Dim Address as OraObject '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&) 'create a dynaset object from person_tab set OraDynaset = OraDatabase.CreateDynaset("select * from person_tab",0&) 'retrieve a address column from person_tab. Here Value property of OraField 'object returns Address OraObject set Address = OraDynaset.Fields("Addr").Value 'access the attribute by dot notation msgbox Address.Street 'access the attribute using '!' notation ( early binding application) msgbox Address!Street 'access the attribute by index msgbox Address(1) 'access the attribute by name msgbox Address("Street") 'access all the attributes of Address OraObject in the dynaset Do Until OraDynaset.EOF For index = 1 To Address.Count msgbox Address(index) Next Index OraDynaset.MoveNext Loop
Example: Updating Attributes of an OraObject Object
The following examples modify the attributes of the ADDRESS
value instance in the database.
Dynaset Example
Dim OraSession as OraSession Dim OraDatabase as OraDatabase Dim OraDynaset as OraDynaset Dim Address as OraObject '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&) 'create a dynaset object from person_tab set OraDynaset = OraDatabase.CreateDynaset("select * from person_tab", 0&) 'retrieve a address column from person_tab. 'Here Value property of OraField object returns Address OraObject set Address = OraDynaset.Fields("Addr").Value 'start the Edit operation and modify the Street attribute OraDynaset.Edit Address.Street = "Oracle Parkway" OraDynaset.Update
Parameter Example
Dim OraSession as OraSession Dim OraDatabase as OraDatabase Dim Address as OraObject '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&) 'create an OraParameter object represent Address object bind Variable OraDatabase.Parameters.Add "ADDRESS", Empty, ORAPARM_INPUT, ORATYPE_OBJECT, _ "ADDRESS" 'get the uninitialized 'Empty' Address object from OraParameter set Address = OraDatabase.Parameters("ADDRESS").Value 'modify the 'Street' attribute of the Address Address.Street = "Oracle Parkway" 'execute the sql statement which updates Address in the person_tab OraDatabase.ExecuteSQL ("update person_tab set addr = :ADDRESS where age = 40")
Example: Inserting an OraObject Object
The following examples insert a new field (value instance) called ADDRESS
in the database.
Dynaset Example
Dim OraSession as OraSession Dim OraDatabase as OraDatabase Dim OraDynaset as OraDynaset Dim AddressNew as OraObject '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&) 'create a dynaset object from person_tab set OraDynaset = OraDatabase.CreateDynaset("select * from person_tab", 0&) ' create a new Address object in OO4O set AddressNew = OraDatabase.CreateOraObject("ADDRESS") 'initialize the Address object attribute to new value AddressNew.Street = "Oracle Parkway" AddressNew.State = "CA" 'start the dynaset AddNew operation and set the Address field to new address ' value OraDynaset.Addnew OraDynaset.Fields("ADDR").Value = AddressNew OraDynaset.Update
OraParameter Example
Dim OraSession as OraSession Dim OraDatabase as OraDatabase Dim OraDynaset as OraDynaset Dim AddressNew as OraObject '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&) 'create an OraParameter object represent Address object bind Variable OraDatabase.Parameters.Add "ADDRESS", Null, ORAPARM_INPUT, ORATYPE_OBJECT, _ "ADDRESS" ' create a new Address object in OO4O set AddressNew = OraDatabase.CreateObject("ADDRESS") 'initialize the Address object attribute to new value AddressNew.Street = "Oracle Parkway" AddressNew.State = "CA" 'set the Address to ADDRESS parameter Oradatabase.Parameters("ADDRESS").Value = AddressNew 'execute the sql statement which updates Address in the person_tab OraDatabase.ExecuteSQL ("insert into person_tab values (30,'Eric',:ADDRESS))
See Also:
"Oracle Object Data Types" for information on support of Oracle object-relational features