OracleRefereceCursor 如何从数据库中获取数据?
How does OracleRefereceCursor get data from database?
假设我在 Oracle 数据库中有一个存储过程,它有一个 ref cursor 输出参数。
从 .Net 使用 ODP.Net 我正在尝试从数据库中获取数据,如下所示(我从 http://www.oracle.com/technetwork/articles/dotnet/williams-refcursors-092375.html 中获取)
OracleCommand cmd = new OracleCommand("otn_ref_cursor.get_emp_info", con);
cmd.CommandType = CommandType.StoredProcedure;
// create parameter object for the cursor
OracleParameter p_refcursor = new OracleParameter();
// this is vital to set when using ref cursors
p_refcursor.OracleDbType = OracleDbType.RefCursor;
// this is a function return value so we must indicate that fact
p_refcursor.Direction = ParameterDirection.ReturnValue;
// add the parameter to the collection
cmd.Parameters.Add(p_refcursor);
// create a data adapter to use with the data set
OracleDataAdapter da = new OracleDataAdapter(cmd);
// create the data set
DataSet ds = new DataSet();
// fill the data set
da.Fill(ds);
数据集如何填充记录?是否一次往返数据库服务器一次获取一条记录?
和
一样吗
OracleDataReader dr = cmd.ExecuteReader();
while (reader.Read())
{
//Do Something
}
我认为使用 DataReader 的方法会使每一行往返 db,我的理解正确吗?
每次往返数据库中获取的数据量由 Fetchsize 控制,它是一定的字节数。我忘记了默认大小。您可以通过将 FetchSize 设置为 Rowsize 的倍数来控制它。 ODP.NET 将缓存数据,直到需要获取更多数据。
假设我在 Oracle 数据库中有一个存储过程,它有一个 ref cursor 输出参数。
从 .Net 使用 ODP.Net 我正在尝试从数据库中获取数据,如下所示(我从 http://www.oracle.com/technetwork/articles/dotnet/williams-refcursors-092375.html 中获取)
OracleCommand cmd = new OracleCommand("otn_ref_cursor.get_emp_info", con);
cmd.CommandType = CommandType.StoredProcedure;
// create parameter object for the cursor
OracleParameter p_refcursor = new OracleParameter();
// this is vital to set when using ref cursors
p_refcursor.OracleDbType = OracleDbType.RefCursor;
// this is a function return value so we must indicate that fact
p_refcursor.Direction = ParameterDirection.ReturnValue;
// add the parameter to the collection
cmd.Parameters.Add(p_refcursor);
// create a data adapter to use with the data set
OracleDataAdapter da = new OracleDataAdapter(cmd);
// create the data set
DataSet ds = new DataSet();
// fill the data set
da.Fill(ds);
数据集如何填充记录?是否一次往返数据库服务器一次获取一条记录?
和
一样吗OracleDataReader dr = cmd.ExecuteReader();
while (reader.Read())
{
//Do Something
}
我认为使用 DataReader 的方法会使每一行往返 db,我的理解正确吗?
每次往返数据库中获取的数据量由 Fetchsize 控制,它是一定的字节数。我忘记了默认大小。您可以通过将 FetchSize 设置为 Rowsize 的倍数来控制它。 ODP.NET 将缓存数据,直到需要获取更多数据。