經典 ASP (VBScript) 通過 ADODB.Command 調用 Oracle 存儲過程,演示輸入參數 + 輸出參數模式的完整頁面代碼,包含資料庫端過程定義、ASP 頁面邏輯、測試驗證。
CREATE TABLE cd_bill_log (
bill_id NUMBER,
deal_emp_id NUMBER,
reach_date DATE,
done_date DATE,
bill_status VARCHAR2(10),
deal_dept_id NUMBER,
sign NUMBER,
remark VARCHAR2(50)
);
CREATE OR REPLACE PROCEDURE cd_update_log (
p_inputremark IN VARCHAR2,
p_msg OUT NUMBER
) AS
BEGIN
UPDATE cd_bill_log a
SET a.remark = p_inputremark
WHERE a.bill_id = 45;
p_msg := 1;
COMMIT;
END cd_update_log;
/
<!--#include file="incpublic.asp"-->
<!--#include file="incconn.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Oracle Stored Proc Call Demo</title>
</head>
<body>
<%
Dim sp_common
Set sp_common = Server.CreateObject("ADODB.Command")
With sp_common
.ActiveConnection = conn ' incconn.asp 中已建立的 Connection 對象
.CommandText = "cd_update_log"
.CommandType = adCmdStoredProc ' 需引用 adovbs.inc 或數值 4
.Parameters.Append .CreateParameter("@inputremark", adVarChar, adParamInput, 50, "聯通.Ye")
.Parameters.Append .CreateParameter("@msg", adInteger, adParamOutput)
.Execute
End With
Dim msg
msg = sp_common("@msg")
Response.Write "<hr>" & msg
Response.End
%>
</body>
</html>
| 項目 | 說明 |
|---|---|
| ADODB.Command | 專門用於執行存儲過程/參數化命令 |
| CommandType = adCmdStoredProc (4) | 告知提供者這是存儲過程調用 |
| Parameters.Append 順序 | 必須與過程定義參數順序一致(Oracle OLE DB 要求) |
| CreateParameter | (Name, Type, Direction, Size, Value) |
| adVarChar / adInteger | 對應 Oracle VARCHAR2 / NUMBER |
| adParamInput / adParamOutput | 方向標識 |
| 輸出參數取值 | sp_common("@msg") 或 sp_common.Parameters("@msg").Value |
OraOLEDB.Oracle Provider,MSDAORA 已棄用Connection.Errors 集合包含 Oracle 詳細錯誤碼