public void invokeProcedure(Int id, out string retCode, out string errMsg, out string result)
{
string sql = "package_name.procedure_name";
OracleParameter[] parms = new OracleParameter[4];
parms[0] = new OracleParameter("p_id", OracleType.Number);
parms[0].Value = id;
parms[1] = new OracleParameter("p_retCode", OracleType.VarChar, 10);
parms[1].Direction = ParameterDirection.Output;
parms[2] = new OracleParameter("p_errMsg", OracleType.VarChar, 50);
parms[2].Direction = ParameterDirection.Output;
parms[3] = new OracleParameter("p_coverinfo", OracleType.VarChar, 50);
parms[3].Direction = ParameterDirection.Output;
try
{
OracleHelper.ExecuteReader(OracleHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, sql, parms).Close();
OracleCommand cmd = new OracleCommand();
OracleConnection conn = new OracleConnection("connectionString");
OracleDataReader rdr;
try
{
//Open the connection if required
if (conn.State != ConnectionState.Open)
conn.Open();
//Set up the command
cmd.Connection = conn;
cmd.CommandText = sql;
cmd.CommandType = CommandType.StoredProcedure;
// Bind the parameters passed in
if (commandParameters != null)
{
foreach (OracleParameter parm in parms)
cmd.Parameters.Add(parm);
}
//Execute the query, stating that the connection should close when the resulting datareader has been read
rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
cmd.Parameters.Clear();
}
catch
{
//If an error occurs close the connection as the reader will not be used and we expect it to close the connection
conn.Close();
throw;
}
rdr.Close();
}
catch
{
retCode = "";
errMsg = "";
coverinfo = "";
return;
}
retCode = parms[1].Value.ToString();
errMsg = parms[2].Value.ToString();
result = parms[3].Value.ToString();
}
c#调用plsql的procedure
最新推荐文章于 2023-12-21 17:13:05 发布