c# 执行调用Oracle Procedure传参及回传值

Posted popo1

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c# 执行调用Oracle Procedure传参及回传值相关的知识,希望对你有一定的参考价值。

////定義參數
               //IDataParameter[] parameters =
               //            
               //                 new OracleParameter(":p_stage", OracleDbType.Varchar2,model.Stage, ParameterDirection.Input),//传值
               //                  new OracleParameter(":ReturnValue", OracleDbType.Varchar2, ParameterDirection.Output)//回传
               //             ;

               ////參數賦值
               ////parameters[0].Value = model.Stage;
               //string prconn = System.Configuration.ConfigurationManager.AppSettings["DBConnStr_tnboa1insert"];
               //OracleConnection conn = new OracleConnection(prconn);
               //conn.Open();
               //OracleCommand cmd = new OracleCommand("PRO__SETTLEMENT", conn);  //Procedure &连接数据库
               //cmd.CommandType = CommandType.StoredProcedure;
               //cmd.Parameters.AddRange(parameters);
               //OracleDataAdapter oda = new OracleDataAdapter(cmd);
               //DataTable dt = new DataTable();
               //oda.Fill(dt);
               //conn.Close();
               //string iReturn = cmd.Parameters["RETURNVALUE"].Value.ToString();
               ////return ds.Tables[0];

              // string iReturn = ConnInstance.ExecuteQuery_Sp("PRO_SETTLEMENT", parameters);//执行完成后得到回传的结果



               DataTable dt = new DataTable();
               string prconn = System.Configuration.ConfigurationManager.AppSettings["DBConnStr_tnboa1insert"];
               OracleConnection conn = new OracleConnection(prconn);
               conn.Open();
               OracleCommand cmd = new OracleCommand("PRO_SETTLEMENT",conn);  //Procedure&连接数据库
               //cmd.CommandText = "PRO_SETTLEMENT";  //Procedure

               cmd.CommandType = CommandType.StoredProcedure;

               cmd.Parameters.Add("P_STAGE", OracleDbType.Varchar2).Direction = ParameterDirection.Input;//传值类型定义
                cmd.Parameters["P_STAGE"].Value = model.Stage;//赋值
                cmd.Parameters.Add("RETURNVALUE", OracleDbType.Varchar2,200).Direction = ParameterDirection.Output;//回传  注:回传定义字符长度,忽略会报错

                cmd.ExecuteNonQuery();
                string iReturn = cmd.Parameters["ReturnValue"].Value.ToString();////执行完成后得到回传的结果
                conn.Close();

以上是关于c# 执行调用Oracle Procedure传参及回传值的主要内容,如果未能解决你的问题,请参考以下文章

Oracle Procedure记录

Oracle 存储过程 PROCEDURE

PostgreSQL Oracle 兼容性之存储过程

Oracle中的存储过程(Stored Procedure)

Oracle 存储过程 Procedure

Oracle中function和procedure的区别