OracleRefereceCursor如何从数据库中获取数据?

时间:2016-10-06 18:51:10

标签: c# oracle plsql odp.net

假设我在Oracle db中有一个存储过程,它有一个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,我的理解是否正确?

1 个答案:

答案 0 :(得分:0)

每次往返数据库中获取的数据量由Fetchsize控制,这是一定数量的字节。我忘记了默认大小。您可以通过将FetchSize设置为Rowsize的倍数来控制此操作。 ODP.NET将缓存数据,直到需要获取更多数据。

相关问题