Using ouput parameter of type SYS_refcursor

Mikayil Abdullayev picture Mikayil Abdullayev · Oct 12, 2011 · Viewed 8.9k times · Source

In my database I have a stored procedure with an OUTPUT parameter of type SYS_REFCURSOR. The application side is wrtitten in C#. Can I assign this procedure's output parameter to a Datatable like:

 .............
 OracleConnection con=new OracleConnection(......);
 OracleCommand cmd=new OracleCommand("MyStoredProc",con);
 cmd.CommandType=CommandType.StoredProcedure;
 cmd.Parameters.Add("REC_CUR",OracleType.Cursor).Direction=ParameterDirection.Output;
 con.Open();
 cmd.ExecuteNonQuery();
 DataTable dt=(DataTable)cmd.Parameters["REC_CUR"].value;//is this legal?

Answer

Mikayil Abdullayev picture Mikayil Abdullayev · Oct 14, 2011

Here's the answer to my own question. If the output parametr of a stored procedure is of type SYS_REFCURSOR then the command

cmd.Parameters["REC_CUR"].value

will return an OracleDataReader object, not a table. And there's no implicit , nor explicit cast from OracledataReader to DataTable.