預存程序:
CREATE OR REPLACE PROCEDURE SP_TEST
(
inDTHM in VARCHAR,
outFZR out VARCHAR,
outSJHM out VARCHAR
)
IS
BEGIN
/*返回結果取第一行記錄*/
SELECT fzr,sjhm into outFZR,outSJHM FROM POLICE WHERE dthm = inDTHM and rownum=1;
end;
程序呼叫方法:
一、SQL*Plus方式:
SQL> var a varchar2(20);
SQL> var b varchar2(20);
SQL> exec sp_test('w2412001876',:a,:b);
PL/SQL procedure successfully completed
a
---------
張三
b
---------
013688888888
二、PL/SQL方式:
SQL視窗
declare fzr varchar2(20);
sjhm varchar2(20);
begin
sp_test('w2412001876',fzr,sjhm );
dbms_output.put_line(fzr);
dbms_output.put_line(sjhm);
end;
命令視窗
SQL> var a varchar2(20);
SQL> var b varchar2(20);
SQL> exec sp_test('w2412001876',:a,:b);
PL/SQL procedure successfully completed
a
---------
張三
b
---------
013688888888
三、VB的ADO方式:
gDBName = Trim(txtDBName.Text)
gDBUser = Trim(txtUserID.Text)
gDBPass = Trim(txtPassID.Text)
Set adoConn = New ADODB.Connection
adoConn.Open "Provider=OraOLEDB.Oracle;Password=" + gDBPass + ";User ID=" + gDBUser + ";Data Source=" + gDBName
If adoConn.State <> adStateOpen Then
MsgBox "資料庫連接失敗,請重新設定參數!", vbExclamation, "系統提示"
Exit Sub
End If
Set adoCommand = New ADODB.Command
Set adoCommand.ActiveConnection = adoConn
adoCommand.CommandText = "SP_TEST"
adoCommand.CommandType = adCmdStoredProc
adoCommand.Parameters.Append adoCommand.CreateParameter("inDTHM", adVarChar, adParamInput, 20, Trim(txtDTHM.Text))
adoCommand.Parameters.Append adoCommand.CreateParameter("outFZR", adVarChar, adParamOutput, 20)
adoCommand.Parameters.Append adoCommand.CreateParameter("outSJHM", adVarChar, adParamOutput, 20)
adoCommand.Execute
txtFZR.Text = CStr(adoCommand("outFZR"))
txtSJHM.Text = CStr(adoCommand("outSJHM"))