[C#对Oracle操作]C#操作调用Orcale存储过程有参数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[C#对Oracle操作]C#操作调用Orcale存储过程有参数相关的知识,希望对你有一定的参考价值。

/// <summary>
        /// 获取ERP固定资产计提数据
        /// </summary>
        /// <param name="strCompanyCode">公司代码</param>
        /// <param name="strClient">应用环境</param>
        /// <param name="strLanguage">语言</param>
        /// <param name="strRealDeprarea">账套代码:‘01’、‘02’、‘03’</param>
        /// <param name="strFiscalYear">会计年度</param>
        /// <param name="strMonth">会计月度:‘mm’</param>
        /// <returns>DataTable数据集</returns>
        public static DataTable getData(string strCompanyCode, string strClient, string strLanguage, string strRealDeprarea, string strFiscalYear, string strMonth)
        {
            OracleConnection myOracleConnection = null;
            try
            {

                DataTable dt = new DataTable();
                myOracleConnection = new OracleConnection();
                myOracleConnection.ConnectionString = ConfigurationManager.ConnectionStrings["FTERP"].ConnectionString;
                myOracleConnection.Open();
                OracleCommand cmd = new OracleCommand("FXA_MAINVALUEINFO", myOracleConnection);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("v_companycode", OracleType.Char).Direction = ParameterDirection.Input; //指明传入的参数是给Oracle存储过程用的
                cmd.Parameters["v_companycode"].Value = strCompanyCode;
                cmd.Parameters.Add("v_client", OracleType.Char).Direction = ParameterDirection.Input;
                cmd.Parameters["v_client"].Value = strClient;
                cmd.Parameters.Add("v_language", OracleType.Char).Direction = ParameterDirection.Input;
                cmd.Parameters["v_language"].Value = strLanguage;
                cmd.Parameters.Add("v_realdeprarea", OracleType.Char).Direction = ParameterDirection.Input;
                cmd.Parameters["v_realdeprarea"].Value = strRealDeprarea;
                cmd.Parameters.Add("v_fiscalyear", OracleType.Char).Direction = ParameterDirection.Input;
                cmd.Parameters["v_fiscalyear"].Value = strFiscalYear;
                cmd.Parameters.Add("v_postperiod", OracleType.Char).Direction = ParameterDirection.Input;
                cmd.Parameters["v_postperiod"].Value = strMonth;
                cmd.Parameters.Add("v_returnvalue", OracleType.Float).Direction = ParameterDirection.Output;
                OracleDataAdapter da = new OracleDataAdapter(cmd);
                da.Fill(dt);
                string eval = cmd.Parameters["v_returnvalue"].Value.ToString();
                //myOracleConnection.Close();
                DataTable dtResult = dt.Clone();
                foreach (DataRow dr in dt.Rows)
                {
                    dtResult.Rows.Add(dr.ItemArray);
                }
                return dtResult;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
                if (myOracleConnection.State == ConnectionState.Open)
                {
                    myOracleConnection.Close();
                }
            }


        }
如下是Oracle的存储过程

CREATE OR REPLACE PROCEDURE BZREPDB.FXA_MAINVALUEINFO (
   v_companycode    IN     CHAR,
   v_client         IN     CHAR,
   v_language       IN     CHAR,
   v_realdeprarea   IN     CHAR,
   v_fiscalyear     IN     CHAR,
   v_postperiod     IN     CHAR,
   v_returnvalue       OUT NUMBER
)

 

以上是关于[C#对Oracle操作]C#操作调用Orcale存储过程有参数的主要内容,如果未能解决你的问题,请参考以下文章

C# 对本机互操作的限制

C#调用替换后Oracle包无效

C#操作MongoDB实现自增列怎么写

从 C# 调用 oracle 函数

如何使用C#操作WinAPI

C#:Oracle 数据类型与 OracleDbType 等价