威凡网全力打造:网页编程、软件开发编程、平面设计、服务器端开发、操作系统等在线学习平台!学编程,上威凡网!
ASP教程>> ASP基础 应用技巧 数据库相关 ASP类 存储过程 FSO专栏 ASP其他
当前位置:首页 > ASP教程 > 数据库相关
上一节 下一节
 Asp Oracle存储过程返回结果集的代码
经过摸索和实践,我把自己的解决方法,写在下面:
说明:
我的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

申明:本教程内容由威凡网编辑整理并提供IT程序员分享学习,如文中有侵权行为,请与站长联系(QQ:254677821)!
上一节 下一节
相关教程  
其他教程  
ASP基础
应用技巧
数据库相关
ASP类
存储过程
FSO专栏
ASP其他

违法和不良信息举报中心】邮箱:254677821@qq.com
Copyright©威凡网 版权所有 苏ICP备2023020142号
站长QQ:254677821