1.返回数组 (作者:.NET/Message_Board/Send.ASP?sendto=enhydraboy" target=_blank>enhydraboy(乱舞的浮尘) )
在ORACLE后台创建一个程序包或者存储过程
connect SCOtt/tiger;
CREATE OR REPLACE PACKAGE ado_callpkg AS
TYPE eid IS TABLE of NUMBER(4) INDEX BY BINARY_INTEGER;
TYPE ename IS TABLE of VARCHAR2(40) INDEX BY BINARY_INTEGER;
PROCEDURE getEmpNames (empid OUT eid,empname OUT ename);
end ado_callpkg;
CREATE OR REPLACE PACKAGE BODY ado_callpkg AS
PROCEDURE getEmpNames (empid OUT eid,empname OUT ename) IS
CURSOR c1 IS select employee_id,first_name||','||Middle_Initial||','||last_name as name from employee;
cnt NUMBER DEFAULT 1;
c c1%ROWTYPE;
BEGIN
open c1;
Loop
FETCH c1 INTO c;
empname(cnt):=c.name;
empid(cnt):=c.employee_id;
EXIT WHEN c1%NOTFOUND; -- process the data
cnt :=cnt+1;
END LOOP;
close c1;
END;
end ado_callpkg;
2 前台vb程序调用
Dim cn As New ADOdb.Connection
Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.Command
Dim str As String
str = "{call ado_callpkg.getEmpNames({resultset 100,empid,empname})}"
cn.Open "Provider=MSDAORA.1;Password=tiger;User ID=scott;Data source=ORACLE;Persist Security Info=True"
With cmd
.CommandText = str
.ActiveConnection = cn
.CommandType = adCmdText
End With
rs.CursorLocation = adUseClient
rs.Open cmd
Do While Not rs.EOF
Debug.Print rs.Fields(0).Value & vbTab & rs.Fields(1).Value
rs.MoveNext
Loop
------------
总结
1 oracle的后台存储过程,应该通过一个类似数组并且带有数字索引的变量返回,有多少个列,就有对应多少个变量
2 前台,调用的sql语句写法要注意,
{call .(,,....,{resultset ,,,...})}
注意的细节,
(1) 要自己指定一个数字,表示接受的行数大小,如果太小,而实际返回的记录大于这个数字,会出错
(2) 如果有输入参数,应该在command中创建输入参数,对应的地方用?替代,如
{call ado_callpkg.getEmpNames(?,{resultset 100,empid,empname})}
(3) output和你存储函数的定义一致,参数名要一样,次序也一样,否则也会出错。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752043/viewspace-956699/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10752043/viewspace-956699/