To call an Oracle stored procedure, the stored procedure must be encapsulated within a package. The following sample uses an Oracle package that was assembled as an example in the Microsoft Knowledge Base article below:
174981 How To Retrieve Typical Resultsets from Oracle Stored Procedures
The script sample below does not use a Data Source Name (DSN) to connect to Oracle. It uses a DSN-less connection. (You can use a system DSN by commenting out the appropriate lines.) The sample uses ODBC to connect to Oracle.
Note that you could also use the Microsoft OLE DB Provider for Oracle in this sample. To do so, comment out the appropriate lines.
<%@ LANGUAGE="VBSCRIPT" %>
<%
'Constants
adCmdUnknown = 0
adCmdText = 1
adCmdTable = 2
adCmdText = 1
adParamInput = 1
adParamOutput = 2
adInteger = 3
adUseClient = 3
adOpenStatic = 3
Dim cnnOracle
Dim cmdStoredProc
Dim rsEmp
'This code creates a connection object.
Set cnnOracle = Server.CreateObject("ADODB.Connection")
cnnOracle.CursorLocation = adUseClient
'System DSN connection
'strConn = "DSN=OracleDSN; UID=UserID; PWD=Password"
'DSN-less connection
strConn = "DRIVER={Microsoft ODBC for Oracle}; SERVER=DatabaseAlias; UID=UserID; PWD=Password"
'OLE DB connection
'strConn = "Provider=MSDAORA.1; Data Source=DatabaseAlias; User ID=UserID; Password=Password"
'Note: The DatabaseAlias is the name that was created in SQL*Net Easy Configuration or in Net8.
cnnOracle.Open strConn
'This code creates a command object.
Set cmdStoredProc = Server.CreateObject("ADODB.Command")
Set cmdStoredProc.ActiveConnection = cnnOracle
'Retrieve only one record
'cmdStoredProc.CommandText = "{call packperson.oneperson(?,{resultset 2, ssn, fname, lname})}"
'cmdStoredProc.CommandType = adCmdText
'cmdStoredProc.Parameters.Append cmdStoredProc.CreateParameter("wildcard",adInteger,adParamInput)
'Retrieve all records.
cmdStoredProc.CommandText = "{call packperson.allperson({resultset 9, ssn, fname, lname})}"
cmdStoredProc.CommandType = adCmdText
'This code creates a recordset object.
Set rsEmp = Server.CreateObject("ADODB.Recordset")
rsEmp.CursorType = adOpenStatic
Set rsEmp.Source = cmdStoredProc
'Set the parameter for to get only one record
'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>Retrieving a Recordset from an Oracle Stored Procedure using ADO on ASP</TITLE>
</HEAD>
<BODY>
<%
'Traverse through the recordset and display the data
While Not rsEmp.EOF
Response.Write(rsEmp(0) & " " & rsEmp(1) & " " & rsEmp(2) & "<BR>")
rsEmp.MoveNext
Wend
' Close the Recordset and the Connection
rsEmp.Close
cnnOracle.Close
' Dereference the ADO Objects
Set cmdStoredProc = nothing
Set rsEmp = nothing
Set cnnOracle = nothing
%>
</BODY>
</HTML>