Oracle调用存储过程
Oracle调用存储过程
pl/sql执行:
SQL窗口:
call procedure_name(parameter);
begin procedure_name(parameter); end;
COMMAND窗口:
exec procedure_name(parameter);
execute procedure_name(parameter);
call procedure_name(parameter);
begin procedure_name(parameter); end;
.net程序执行:
public bool UpdateDate(int xzID, int stewardID)
{
bool result = false;
OracleCommand oraCmd = new OracleCommand();
oraCmd.CommandText = "xx.Sp_update"; //存储过程名称
oraCmd.CommandType = CommandType.StoredProcedure;
#region 存储过程的参数声明
OracleParameter[] parameters ={
new OracleParameter("i_xz_id",OracleType.Number),
new OracleParameter("i_steward_id",OracleType.Number)
};
parameters[0].Value = xzID;
parameters[0].Direction = ParameterDirection.Input;
parameters[1].Value = stewardID;
parameters[1].Direction = ParameterDirection.Input;
#endregion
oraCmd.Parameters.AddRange(parameters);
result =SetData(oraCmd, OracleConnection);
return result;
}
public DataTable GetData(OracleCommand cmd, OracleConnection cn)
{
cmd.Connection = cn;
OracleDataAdapter oda = new OracleDataAdapter(cmd);
DataTable tb = new DataTable();
try
{
cn.Open();
oda.Fill(tb);
}
catch (Exception e)
{
throw e;
}
finally
{
if (cn.State == ConnectionState.Open)
{
cn.Close();
}
}
return tb;
}
public bool SetData(OracleCommand cmd, OracleConnection cn)
{
cmd.Connection = cn;
try
{
cn.Open();
//int i =
cmd.ExecuteNonQuery();
//if(i>0)
//{
return true;
//}
//return false;
}
catch (Exception ee)
{
throw ee;
}
finally
{
if (cn.State == ConnectionState.Open)
{
cn.Close();
}
}
}