vb 调用 Oracle 函数返回数据集的例子
2024-07-21 02:24:55
供稿:网友
pl/sql 代码:
create or replace package "scott"."pkg_test" as
type myrctype is ref cursor;
function get(strbarcode varchar) return myrctype;
end pkg_test;
create or replace package body "scott"."pkg_test" as
function get(strbarcode in varchar) return myrctype is
rc myrctype;
begin
open rc for strbarcode;
return rc;
end get;
end pkg_test;
--------------------------------------------------------------------------------------------------------
vb 代码:
private sub command1_click()
on error goto cursorerr:
dim cnn as new adodb.connection
dim rst as new adodb.recordset
dim cmd as new adodb.command
cnn.connectionstring = "provider=oraoledb.oracle.1;password=tiger;persist security info=true;user id=scott;data source=oraany;extended properties=plsqlrset=1"
cnn.open
with cmd
.activeconnection = cnn
.commandtype = adcmdtext
.commandtext = "{call scott.pkg_test.get(?)}"
.parameters.append .createparameter("strbarcode", advarchar, adparaminput, 100, "select * from tab")
end with
rst.cursortype = adopenstatic
rst.locktype = adlockreadonly
set rst.source = cmd
rst.open
msgbox rst.recordcount
set rst = nothing
set cmd = nothing
exit sub
cursorerr:
set cmd = nothing
set rst1 = nothing
msgbox err.description
end sub