Skip Headers
Oracle® Objects for OLE Developer's Guide
11g Release 2 (11.2) for Microsoft Windows

Part Number E12245-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

CreateIterator Method

Applies To

OraCollection Object

Description

Creates an iterator to scan the elements of a collection.

Usage

OraCollection.CreateIterator

Remarks

This method creates an iterator for scanning the elements of an Oracle collection. Accessing collection elements using the iterator is faster than using an index on the instance of a collection.

Examples

Example: OraCollection Iterator

The following example illustrates the use of an Oracle collection iterator.

Before running the sample code, make sure that you have the necessary data types and tables in the database. See "Schema Objects Used in OraCollection Examples" .

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