如何调用Oracle存储过程?
来源:asp之家 时间:2009-11-15 20:13:00
请问如何在ASP中使用ADO调用Oracle的存储过程?
我们可以在下面的代码里使用微软Oracle 的OLE DB Provider ,包括说明:
<%@ LANGUAGE="VBSCRIPT" %>
<%
adCmdUnknown = 0
adCmdText = 1
adCmdTable = 2
adCmdText = 1
adParamInput = 1
adParamOutput = 2
adInteger = 3
adUseClient = 3
adOpenStatic = 3
' 常量
Dim cnnOracle
Dim cmdStoredProc
Dim rsEmp
Set cnnOracle = Server.CreateObject("ADODB.Connection")
cnnOracle.CursorLocation = adUseClient
' 创建连接对象
'strConn = "DSN=OracleDSN; UID=UserID; PWD=Password"
' 系统DSN连接
strConn = "DRIVER={Microsoft ODBC for Oracle}; SERVER=DatabaseAlias; UID=UserID; PWD=Password"
' DSN-less 连接,DatabaseAlias是在SQL*Net Easy Configuration 或Net8里创建的名字
'strConn = "Provider=MSDAORA.1; Data Source=DatabaseAlias; User ID=UserID; Password=Password"
' OLE DB 连接
cnnOracle.Open strConn
Set cmdStoredProc = Server.CreateObject("ADODB.Command")
Set cmdStoredProc.ActiveConnection = cnnOracle
' 创建一个命令对象
'cmdStoredProc.CommandText = "{call packperson.oneperson(?,{resultset 2, ssn, fname, lname})}"
'cmdStoredProc.CommandType = adCmdText
'cmdStoredProc.Parameters.Append cmdStoredProc.CreateParameter("wildcard",adInteger, adParamInput)
' 只检索一条记录
cmdStoredProc.CommandText = "{call packperson.allperson({resultset 9, ssn, fname, lname})}"
cmdStoredProc.CommandType = adCmdText
' 检索所有记录
Set rsEmp = Server.CreateObject("ADODB.Recordset")
rsEmp.CursorType = adOpenStatic
' 创建记录集对象
Set rsEmp.Source = cmdStoredProc
'cmdStoredProc(0) = 555662222
' 为只获取一条记录设置参数
rsEmp.Open
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual InterDev 6.0">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>精彩春风之调用Oracle存储过程</TITLE>
</HEAD>
<BODY>
<%
While Not rsEmp.EOF
Response.Write(rsEmp(0) & " " & rsEmp(1) & " " & rsEmp(2) & "<BR>")
rsEmp.MoveNext
' 遍历记录集并显示数据
Wend
rsEmp.Close
cnnOracle.Close
' 关闭记录集和连接
Set cmdStoredProc = nothing
Set rsEmp = nothing
Set cnnOracle = nothing
%>
</BODY>
</HTML>