主页 > 编程资料 > C# >
发布时间:2015-09-26 作者:网络 阅读:244次

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

关键字词: