欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Asp Oracle存储过程返回结果集的代码

程序员文章站 2022-05-18 11:13:57
经过摸索和实践,我把自己的解决方法,写在下面: 说明: 我的oracle客户端的版本是 oracle 9i, 安装client端的时候,不能用默认安装,一定要自定义, 然后...
经过摸索和实践,我把自己的解决方法,写在下面:
说明:
我的oracle客户端的版本是 oracle 9i, 安装client端的时候,不能用默认安装,一定要自定义, 然后选择所有 oledb 相关的内容,都装上,否则到下面的 provider 的时候,会找不到。
复制代码 代码如下:

<%@language="vbscript" codepage="936" lcid="2052"%>
<%option explicit%>
<!-- #include file="../adovbs.inc" -->
<%
dim cnora
function connect2oracleserver
dim constr
constr = "provider=msdaora.oracle;data source=xx;user id=?;password=?"
set cnora = server.createobject("adodb.connection")
cnora.cursorlocation = aduseclient '=3
on error resume next
cnora.open constr
connect2oracleserver = (err.number = 0)
end function
sub disconnectfromoracleserver
if not cnora is nothing then
if cnora.state = 1 then
cnora.close
end if
set cnora = nothing
end if
end sub
sub echo(str)
response.write(str)
end sub
sub outputresult
dim cmdora
dim rs
set cmdora = server.createobject("adodb.command")
with cmdora
.commandtype = adcmdtext '=1
.commandtext = "{call pkg_test.getitem(?,?)}"
.parameters.append cmdora.createparameter("p1", adnumeric, adparaminput, 10, 1)
.parameters.append cmdora.createparameter("p2", advarchar, adparaminput, 10, "xx")
.activeconnection = cnora
set rs = cmdora.execute
if not rs.eof then
while not rs.eof
echo rs(0)
echo "--"
echo rs(1)
echo "<br>"
rs.movenext
wend
rs.close
end if
set rs = nothing
set cmdora = nothing
end with
disconnectfromoracleserver
end sub
if connect2oracleserver then
outputresult
else
response.write(err.description)
end if
%>

下面是 oracle 的 sql 脚本
--------------------------------------sql script----------------------------------
--建包-----------------------------------
复制代码 代码如下:

create or replace package pkg_test
is
type rfctest is ref cursor ;
procedure getitem
( p1 in number,
p2 in varchar2,
p3 out rfctest
);
end; -- package specification pkg_test
---------------------------------------------------
--建包体-----------------------------------
create or replace package body pkg_test
is
procedure getitem
( p1 in number,
p2 in varchar2,
p3 out rfctest
)
is
begin
open p3 for
select * from tablename where id = p1 and name=p2 and rownum < 10 ;
exception
when others then
null ;
end;
end; -- package body pkg_test