Article ID: 174679
Article Last Modified on 3/2/2005
CREATE OR REPLACE PACKAGE SimplePackage AS
TYPE t_id is TABLE of NUMBER(5)
INDEX BY BINARY_INTEGER;
TYPE t_Course is TABLE of VARCHAR2(10)
INDEX BY BINARY_INTEGER;
TYPE t_Dept is TABLE of VARCHAR2(5)
INDEX BY BINARY_INTEGER;
TYPE t_pk1Type1 IS TABLE OF VARCHAR2(100)
INDEX BY BINARY_INTEGER;
TYPE t_pk1Type2 IS TABLE OF NUMBER(5)
INDEX BY BINARY_INTEGER;
PROCEDURE proc1
( o_id OUT t_id,
ao_course OUT t_Course,
ao_dept OUT t_Dept
);
PROCEDURE proc2
(
i_Arg1 IN NUMBER,
ao_Arg2 OUT t_pk1Type1,
ao_Arg3 OUT t_pk1Type2
);
END SimplePackage;
CREATE OR REPLACE PACKAGE BODY SimplePackage AS
PROCEDURE proc1
(
o_id OUT t_id,
ao_course OUT t_Course,
ao_dept OUT t_Dept
)
AS
BEGIN
o_id(1):= 200;
ao_course(1) := 'M101';
ao_dept(1) := 'EEE' ;
o_id(2) := 201;
ao_course(2) := 'PHY320';
ao_dept(2) := 'ECE' ;
END proc1;
PROCEDURE proc2
(
i_Arg1 IN NUMBER,
ao_Arg2 OUT t_pk1Type1,
ao_Arg3 OUT t_pk1Type2
)
AS
i NUMBER;
BEGIN
FOR i IN 1 .. i_Arg1 LOOP
ao_Arg2(i) := 'Row Number ' || to_char(i);
END LOOP;
FOR i IN 1 .. i_Arg1 LOOP
ao_Arg3(i) := i;
END LOOP;
END proc2;
END SimplePackage;
Once SimplePackage is loaded and compiled on the Oracle server, you can
start working on the Visual Basic application.
Control Name Text/Caption
----------------------------------
Button cmdProc1A Proc1A
Button cmdProc1B Proc1B
Button cmdProc2A Proc2A
Button cmdProc2B Proc2B
Text Box txtZero1
Text Box txtZero2
Text Box txtOne1
Text Box txtOne2
txtZero1 txtOne1
txtZero2 txtOne2
Option Explicit
Dim Cn As rdoConnection
Dim En As rdoEnvironment
Dim CPw1 As rdoQuery
Dim CPw2 As rdoQuery
Dim CPw3 As rdoQuery
Dim CPw4 As rdoQuery
Dim Rs As rdoResultset
Dim Conn As String
Dim QSQL As String
Private Sub cmdProc1A_Click()
Set Rs = CPw1.OpenResultset(rdOpenStatic, rdConcurReadOnly)
txtZero1 = Rs(0)
txtOne1 = Rs(1) & " " & Rs(2)
Rs.MoveNext
txtZero2 = Rs(0)
txtOne2 = Rs(1) & " " & Rs(2)
Rs.Close
MsgBox "Done"
End Sub
Private Sub cmdProc1B_Click()
Dim tempOne1 As String
Dim tempOne2 As String
Set Rs = CPw2.OpenResultset(rdOpenForwardOnly, rdConcurReadOnly)
txtZero1 = Rs(0)
Rs.MoveNext
txtZero2 = Rs(0)
Rs.MoreResults
tempOne1 = Rs(0)
Rs.MoveNext
tempOne2 = Rs(0)
Rs.MoreResults
txtOne1 = tempOne1 & " " & Rs(0)
Rs.MoveNext
txtOne2 = tempOne2 & " " & Rs(0)
Rs.Close
MsgBox "Done"
End Sub
Private Sub cmdProc2A_Click()
CPw3(0) = 2
Set Rs = CPw3.OpenResultset(rdOpenForwardOnly, rdConcurReadOnly)
txtZero1 = Rs(0)
txtOne1 = Rs(1)
Rs.MoveNext
txtZero2 = Rs(0)
txtOne2 = Rs(1)
Rs.Close
MsgBox "Done"
End Sub
Private Sub cmdProc2B_Click()
CPw4(0) = 2
Set Rs = CPw4.OpenResultset(rdOpenForwardOnly, rdConcurReadOnly)
txtZero1 = Rs(0)
Rs.MoveNext
txtZero2 = Rs(0)
Rs.MoreResults
txtOne1 = Rs(0)
Rs.MoveNext
txtOne2 = Rs(0)
Rs.Close
MsgBox "Done"
End Sub
Private Sub Form_Load()
Conn = "UID=<user ID>;PWD=<password>;"_
& "driver={Microsoft ODBC for Oracle};SERVER=RonOracle;"
Set En = rdoEnvironments(0)
En.CursorDriver = rdUseOdbc
Set Cn = En.OpenConnection("", rdDriverNoPrompt, False, Conn)
QSQL = "{call SimplePackage.Proc1({resultset 3, o_id , " _
& "ao_course, ao_dept})}"
Set CPw1 = Cn.CreateQuery("", QSQL)
QSQL = "{call SimplePackage.Proc1({resultset 3, o_id}, " _
& "{resultset 3, ao_course}, {resultset 3, ao_dept})}"
Set CPw2 = Cn.CreateQuery("", QSQL)
QSQL = "{call SimplePackage.Proc2(?,{resultset 3, ao_Arg2," _
& " ao_Arg3})}"
Set CPw3 = Cn.CreateQuery("", QSQL)
QSQL = "{call SimplePackage.Proc2(?,{resultset 3, ao_Arg2}, " _
& "{resultset 3, ao_Arg3})}"
Set CPw4 = Cn.CreateQuery("", QSQL)
End Sub
Private Sub Form_Unload(Cancel As Integer)
En.Close
End Sub
QSQL = "{call SimplePackage.Proc1({resultset 3, o_id , " _
& "ao_course, ao_dept})}"
Within the call statement, you must supply the keyword RESULTSET followed by the maximum number of rows you will be returning.
QSQL = "{call SimplePackage.Proc1({resultset 3, o_id}, " _
& "{resultset 3, ao_course}, {resultset 3, ao_dept})}"
This form of the call statement is actually creating three resultsets; one
for each column in the original (or returning) resultset. Note that you
must use the keyword RESULTSET and the maximum number of rows for each
resultset. This form of the call statement is actually giving the resultset
for each array declared in the parameter list.
QSQL = "{call SimplePackage.Proc2(?,{resultset 3, ao_Arg2,"
& " ao_Arg3})}"
Note that not much has changed. An input placeholder (?) has been added to
the beginning of the parameter list, where it must be if it is to be used.
QSQL = "{call SimplePackage.Proc2(?,{resultset 3, ao_Arg2}, " _
& "{resultset 3, ao_Arg3})}"
Once the query object is defined, everything else in the project is
standard RDO; setting input and output parameters, moving within the RDO
resultsets, and moving between resultsets.167225 How To Access an Oracle Database Using RDO
Keywords: kbhowto kboracle kbrdo kbdatabase kbdriver KB174679