Oracle® Objects for OLE Developer's Guide 10g Release 1 (10.1) Part Number B10118-01 |
|
The following example illustrates the use of an Oracle collection iterator .Before running the sample code, make sure that you have the necessary datatypes and tables in the database. See Schema Description used in examples of OraCollection.
Dim OraSession As OraSession
Dim OraDatabase As OraDatabase
Dim OraDynaset As OraDynaset
Dim CourseList As OraCollection
Dim Course 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 division
Set OraDynaset = OraDatabase.CreateDynaset("select courses from
division where name='History'", 0&)
'Retrieve a Courses column from Division.
Set CourseList = OraDynaset.Fields("Courses").Value
'Create the iterator
CourseList.CreateIterator
'Initialize the iterator to point to the beginning of a collection
CourseList.InitIterator
'Call IterNext to read CourseList until the end
While CourseList.EOC = False
Set Course = CourseList.ElementValue
course_no = Course.course_no
Title = Course.Title
Credits = Course.Credits
CourseList.IterNext
Wend
'Call IterPrev to read CourseList until the beginning
CourseList.IterPrev
While CourseList.BOC = False
Set Course = CourseList.ElementValue
course_no = Course.course_no
Title = Course.Title
Credits = Course.Credits
CourseList.IterPrev
Wend