Asp Oracle預存程序返回結果集的代碼

來源:互聯網
上載者:User

經過摸索和實踐,我把自己的解決方案,寫在下面:
說明:
我的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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.