Stored Proc returns a Cursor, how to handle this u

2019-05-29 00:37发布

问题:

I am using OLEDB driver to call a Stored Procedure in Oracle DB. The Stored Proc returns a cursor as the output. I am able to call this Stored Proc using Oracle Data Source (System.Data.Oracle.OracleCommand), However I do not know how to call this SP using the OLEDB data source. Any help on how to specify the SP is returning a cursor as the output using OLEDB would be greatly appreciated.


private static OracleCommand CreateOraStoredProcCmd()
                {
                        string storedProcName = "pkg_query.prc_get_my_trades";
                        OracleCommand cmd = new OracleCommand(storedProcName);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("book_list", "Jan, Feb");
                        cmd.Parameters.AddWithValue("maturity_date_start", DateTime.Now.ToString("dd-MMM-yyyy"));
                        cmd.Parameters.AddWithValue("maturity_date_end", DateTime.Now.ToString("dd-MMM-yyyy"));
                        cmd.Parameters.AddWithValue("ccy_list", "GBP,USD");
                        cmd.Parameters.Add("trades", OracleType.Cursor).Direction = ParameterDirection.Output;
                        return cmd;
                }

I do not know how to specify the parameter "trades" is an output cursor on the OledbCommand object.

Thanks in advance!

回答1:

The Oracle Provider for OLE DB converts any parameters that reference cursors into an ADO Recordset, but only if PLSQLRSet=1 is added to your connection string.



回答2:

I was having an issue querying an Oracle database,and PLSQLRSet=1 resolved my problem. I just appended it to my connection string (ending with ;).

Carlos A Merighe.