Oracle方面
1.建立Oracle過程儲存
create or replace procedure proce_test(paramin in varchar2,paramout out varchar2,paraminout in out varchar2)
as
varparam varchar2(28);
begin
varparam:=paramin;
paramout:=varparam|| paraminout;
end;
2.測試過程儲存
declare
param_out varchar2(28);
param_inout varchar2(28);
begin
param_inout:='ff';
proce_test('dd',param_out,param_inout);
dbms_output.put_line(param_out);
end;
C#方面
引用Oracle組件
using System;
using System.Data;
using System.Data.OracleClient;
namespace WebApplication4
{
public class OraOprater
{
private OracleConnection conn=null;
private OracleCommand cmd=null;
public OraOprater()
{
string mConn="data source=ora9i.ora.com;user id=ora;password=ora"; //串連資料庫
conn=new OracleConnection(mConn);
try
{
conn.Open();
cmd=new OracleCommand();
cmd.Connection=conn;
}
catch(Exception e)
{
throw e;
}
}
public string SpExeFor(string m_A,string m_B)
{
//預存程序的參數聲明
OracleParameter[] parameters={
new OracleParameter("paramin",OracleType.VarChar,20),
new OracleParameter("paramout",OracleType.VarChar,20),
new OracleParameter("paraminout",OracleType.VarChar,20)
};
parameters[0].Value=m_A;
parameters[2].Value=m_B;
parameters[0].Direction=ParameterDirection.Input;
parameters[1].Direction=ParameterDirection.Output;
parameters[2].Direction=ParameterDirection.InputOutput;
try
{
RunProcedure("proce_test",parameters);
return parameters[1].Value.ToString();
}
catch(Exception e)
{
throw e;
}
}
private void RunProcedure(string storedProcName,OracleParameter[] parameters)
{
cmd.CommandText=storedProcName;//聲明預存程序名
cmd.CommandType=CommandType.StoredProcedure;
foreach(OracleParameter parameter in parameters)
{
cmd.Parameters.Add(parameter);
}
cmd.ExecuteNonQuery();//執行預存程序
}
}
}
測試結果:ddff