GetOracleDataReader

This method returns the OracleDataReader object corresponding to the REF CURSOR type column in the select list.

Declaration

// C#
public OracleDataReader GetOracleDataReader(int index);

Parameters

  • index

    The zero-based column index.

Return Value

The OracleDataReader object of the column.

Expections

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

The application can read data from the returned OracleDataReader object.

The returned OracleDataReader object inherits the FetchSize, InitialLOBFetchSize, InitialLONGFetchSize, and UseEdmMapping property values from OracleDataReader.

Sample

CREATE OR REPLACE FUNCTION refcurfunc1 RETURN SYS_REFCURSOR
AS
   VAR_REF SYS_REFCURSOR;
BEGIN
    OPEN VAR_REF FOR
        SELECT *
        FROM EMP;
    RETURN VAR_REF;
END;

using (OracleConnection con = new OracleConnection("user id = scott; password = <PASSWORD>; data source = oracle"))
{
  con.Open();
 
  OracleCommand cmd = con.CreateCommand();
  cmd.CommandText = "select refcurfunc1() from dual";
  OracleDataReader reader = cmd.ExecuteReader();
 
  while (reader.Read())
  {
    OracleDataReader refCurReader = reader.GetOracleDataReader();
    while (refCurReader.Read())
    {
      Console.WriteLine("RefCursor Data: " + refCurReader.GetString(0));
    }
    refCurReader.Close();
    refCurReader.Dispose();
  }
}