小编典典

从C#调用Oracle存储过程?

c#

如何从C#调用oracle中的存储过程?


阅读 656

收藏
2020-05-19

共1个答案

小编典典

请访问由oracle为Microsoft OracleClient
Developers设置的ODP网站:http
:
//www.oracle.com/technetwork/topics/dotnet/index-085703.html

同样在下面是示例代码,可以帮助您开始从C#到Oracle调用存储过程。PKG_COLLECTION.CSP_COLLECTION_HDR_SELECT是在Oracle上构建的存储过程,接受参数PUNIT,POFFICE,PRECEIPT_NBR并将结果返回到T_CURSOR。

using Oracle.DataAccess;
using Oracle.DataAccess.Client;

public DataTable GetHeader_BySproc(string unit, string office, string receiptno)
{
    using (OracleConnection cn = new OracleConnection(DatabaseHelper.GetConnectionString()))
    {
        OracleDataAdapter da = new OracleDataAdapter();
        OracleCommand cmd = new OracleCommand();
        cmd.Connection = cn;
        cmd.InitialLONGFetchSize = 1000;
        cmd.CommandText = DatabaseHelper.GetDBOwner() + "PKG_COLLECTION.CSP_COLLECTION_HDR_SELECT";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("PUNIT", OracleDbType.Char).Value = unit;
        cmd.Parameters.Add("POFFICE", OracleDbType.Char).Value = office;
        cmd.Parameters.Add("PRECEIPT_NBR", OracleDbType.Int32).Value = receiptno;
        cmd.Parameters.Add("T_CURSOR", OracleDbType.RefCursor).Direction = ParameterDirection.Output;

        da.SelectCommand = cmd;
        DataTable dt = new DataTable();
        da.Fill(dt);
        return dt;
    }
}
2020-05-19