这是msdn中有关返回记录集和vb调用存取过程的办法。DROP TABLE person;CREATE TABLE person (ssn NUMBER(9) PRIMARY KEY, fname VARCHAR2(15), lname VARCHAR2(20));INSERT INTO person VALUES(555662222,'Sam','Goodwin');INSERT INTO person VALUES(555882222,'Kent','Clark');INSERT INTO person VALUES(666223333,'Jane','Doe');COMMIT; / Create the following package on your Oracle server:CREATE OR REPLACE PACKAGE packperson AS TYPE tssn is TABLE of NUMBER(10) INDEX BY BINARY_INTEGER; TYPE tfname is TABLE of VARCHAR2(15) INDEX BY BINARY_INTEGER; TYPE tlname is TABLE of VARCHAR2(20) INDEX BY BINARY_INTEGER; PROCEDURE allperson (ssn OUT tssn, fname OUT tfname, lname OUT tlname); PROCEDURE oneperson (onessn IN NUMBER, ssn OUT tssn, fname OUT tfname, lname OUT tlname); END packperson; / Create the following package body on your Oracle server:CREATE OR REPLACE PACKAGE BODY packperson ASPROCEDURE allperson (ssn OUT tssn, fname OUT tfname, lname OUT tlname) IS CURSOR person_cur IS SELECT ssn, fname, lname FROM person; percount NUMBER DEFAULT 1;BEGIN FOR singleperson IN person_cur LOOP ssn(percount) := singleperson.ssn; fname(percount) := singleperson.fname; lname(percount) := singleperson.lname; percount := percount + 1; END LOOP; END;PROCEDURE oneperson (onessn IN NUMBER, ssn OUT tssn, fname OUT tfname, lname OUT tlname) IS CURSOR person_cur IS SELECT ssn, fname, lname FROM person WHERE ssn = onessn; percount NUMBER DEFAULT 1;BEGIN FOR singleperson IN person_cur LOOP ssn(percount) := singleperson.ssn; fname(percount) := singleperson.fname; lname(percount) := singleperson.lname; percount := percount + 1; END LOOP; END; END; / Open a new project in Visual Basic 5.0 or 6.0 Enterprise edition. Form1 is created by default. Place the following controls on the form: Control Name Text/Caption ----------------------------------------- Button cmdGetEveryone Get Everyone Button cmdGetOne Get One From the Tools menu, select the Options item. Click the "Default Full Module View" option and then click OK. This will allow you to view all of the code for this project. Paste the following code into your code window:Option Explicit Dim Cn As ADODB.Connection Dim CPw1 As ADODB.Command Dim CPw2 As ADODB.Command Dim Rs As ADODB.Recordset Dim Conn As String Dim QSQL As String Dim inputssn As LongPrivate Sub cmdGetEveryone_Click() Set Rs.Source = CPw1 Rs.Open While Not Rs.EOF MsgBox "Person data: " & Rs(0) & ", " & Rs(1) & ", " & Rs(2) Rs.MoveNext Wend Rs.CloseEnd SubPrivate Sub cmdGetOne_Click() Set Rs.Source = CPw2 inputssn = InputBox("Enter the SSN you wish to retrieve:") CPw2(0) = inputssn Rs.Open MsgBox "Person data: " & Rs(0) & ", " & Rs(1) & ", " & Rs(2) Rs.CloseEnd SubPrivate Sub Form_Load() 'Replace <User ID>, <Password>, and <Server> with the 'appropriate parameters. Conn = "UID=*****;PWD=*****;driver=" _ & "{Microsoft ODBC for Oracle};SERVER=dseOracle;" Set Cn = New ADODB.Connection With Cn .ConnectionString = Conn .CursorLocation = adUseClient .Open End With QSQL = "{call packperson.allperson({resultset 9, ssn, fname, " _ & "lname})}" Set CPw1 = New ADODB.Command With CPw1 Set .ActiveConnection = Cn .CommandText = QSQL .CommandType = adCmdText End With QSQL = "{call packperson.oneperson(?,{resultset 2, ssn, fname, " _ & "lname})}" Set CPw2 = New ADODB.Command With CPw2 Set .ActiveConnection = Cn .CommandText = QSQL .CommandType = adCmdText .Parameters.Append .CreateParameter(, adInteger, adParamInput) End With Set Rs = New ADODB.Recordset With Rs .CursorType = adOpenStatic .LockType = adLockReadOnly End WithEnd SubPrivate Sub Form_Unload(Cancel As Integer) Cn.Close Set Cn = Nothing Set CPw1 = Nothing Set CPw2 = Nothing Set Rs = NothingEnd Sub Go to the Project menu item and select References. Select the "Microsoft Active Data Objects 2.x Library." Run the project. When you click on the "Get Everyone" button, it executes this query:QSQL = "{call packperson.allperson({resultset 9, ssn, fname, "_ & "lname})}"
(ssn NUMBER(9) PRIMARY KEY,
fname VARCHAR2(15),
lname VARCHAR2(20));INSERT INTO person VALUES(555662222,'Sam','Goodwin');INSERT INTO person VALUES(555882222,'Kent','Clark');INSERT INTO person VALUES(666223333,'Jane','Doe');COMMIT;
/
Create the following package on your Oracle server:CREATE OR REPLACE PACKAGE packperson
AS
TYPE tssn is TABLE of NUMBER(10)
INDEX BY BINARY_INTEGER;
TYPE tfname is TABLE of VARCHAR2(15)
INDEX BY BINARY_INTEGER;
TYPE tlname is TABLE of VARCHAR2(20)
INDEX BY BINARY_INTEGER; PROCEDURE allperson
(ssn OUT tssn,
fname OUT tfname,
lname OUT tlname);
PROCEDURE oneperson
(onessn IN NUMBER,
ssn OUT tssn,
fname OUT tfname,
lname OUT tlname);
END packperson;
/
Create the following package body on your Oracle server:CREATE OR REPLACE PACKAGE BODY packperson
ASPROCEDURE allperson
(ssn OUT tssn,
fname OUT tfname,
lname OUT tlname)
IS
CURSOR person_cur IS
SELECT ssn, fname, lname
FROM person; percount NUMBER DEFAULT 1;BEGIN
FOR singleperson IN person_cur
LOOP
ssn(percount) := singleperson.ssn;
fname(percount) := singleperson.fname;
lname(percount) := singleperson.lname;
percount := percount + 1;
END LOOP;
END;PROCEDURE oneperson
(onessn IN NUMBER,
ssn OUT tssn,
fname OUT tfname,
lname OUT tlname)
IS
CURSOR person_cur IS
SELECT ssn, fname, lname
FROM person
WHERE ssn = onessn; percount NUMBER DEFAULT 1;BEGIN
FOR singleperson IN person_cur
LOOP
ssn(percount) := singleperson.ssn;
fname(percount) := singleperson.fname;
lname(percount) := singleperson.lname;
percount := percount + 1;
END LOOP;
END;
END;
/
Open a new project in Visual Basic 5.0 or 6.0 Enterprise edition. Form1 is created by default.
Place the following controls on the form:
Control Name Text/Caption
-----------------------------------------
Button cmdGetEveryone Get Everyone
Button cmdGetOne Get One
From the Tools menu, select the Options item. Click the "Default Full Module View" option and then click OK. This will allow you to view all of the code for this project. Paste the following code into your code window:Option Explicit
Dim Cn As ADODB.Connection
Dim CPw1 As ADODB.Command
Dim CPw2 As ADODB.Command
Dim Rs As ADODB.Recordset
Dim Conn As String
Dim QSQL As String
Dim inputssn As LongPrivate Sub cmdGetEveryone_Click() Set Rs.Source = CPw1 Rs.Open While Not Rs.EOF
MsgBox "Person data: " & Rs(0) & ", " & Rs(1) & ", " & Rs(2)
Rs.MoveNext
Wend Rs.CloseEnd SubPrivate Sub cmdGetOne_Click() Set Rs.Source = CPw2 inputssn = InputBox("Enter the SSN you wish to retrieve:") CPw2(0) = inputssn Rs.Open MsgBox "Person data: " & Rs(0) & ", " & Rs(1) & ", " & Rs(2) Rs.CloseEnd SubPrivate Sub Form_Load() 'Replace <User ID>, <Password>, and <Server> with the
'appropriate parameters.
Conn = "UID=*****;PWD=*****;driver=" _
& "{Microsoft ODBC for Oracle};SERVER=dseOracle;" Set Cn = New ADODB.Connection
With Cn
.ConnectionString = Conn
.CursorLocation = adUseClient
.Open
End With QSQL = "{call packperson.allperson({resultset 9, ssn, fname, " _
& "lname})}" Set CPw1 = New ADODB.Command
With CPw1
Set .ActiveConnection = Cn
.CommandText = QSQL
.CommandType = adCmdText
End With QSQL = "{call packperson.oneperson(?,{resultset 2, ssn, fname, " _
& "lname})}" Set CPw2 = New ADODB.Command
With CPw2
Set .ActiveConnection = Cn
.CommandText = QSQL
.CommandType = adCmdText
.Parameters.Append .CreateParameter(, adInteger, adParamInput)
End With Set Rs = New ADODB.Recordset
With Rs
.CursorType = adOpenStatic
.LockType = adLockReadOnly
End WithEnd SubPrivate Sub Form_Unload(Cancel As Integer) Cn.Close
Set Cn = Nothing
Set CPw1 = Nothing
Set CPw2 = Nothing
Set Rs = NothingEnd Sub
Go to the Project menu item and select References. Select the "Microsoft Active Data Objects 2.x Library." Run the project. When you click on the "Get Everyone" button, it executes this query:QSQL = "{call packperson.allperson({resultset 9, ssn, fname, "_
& "lname})}"