Oracle REF CURSOR and Procedures

Oracle REF CURSOR and Procedures

Old forum URL: forums.lhotka.net/forums/t/4520.aspx


dorlett posted on Wednesday, March 19, 2008

This may be too basic a question, if so please forgive...

I'm testing switching from using SQL Server database to Oracle.  By following tips from other posts here, I've successfully tested creating a Package defining a REF CURSOR variable and a Procedure that uses the REF CURSOR variable as an OUT parameter, and successfully retrieved data in my test object using:

    private void ExecuteFetch(OracleConnection cn, FilterCriteria criteria)
    {
        using (OracleCommand cm = cn.CreateCommand())
        {
            cm.CommandType = CommandType.StoredProcedure;
            cm.CommandText = "PACKAGE1.ship_test_select";
            OracleParameter p_refcursor = new OracleParameter("outCursor",OracleType.Cursor);
            p_refcursor.Direction = ParameterDirection.Output;
            cm.Parameters.Add(p_refcursor);

            using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
            {
                while (dr.Read())
                    this.Add(Ship_TestReadOnlyChild.GetShip_TestReadOnlyChild(dr));
                dr.Close();
            }
           
        }//using
    }

I have too many questions, but am I correct in thinking I will need to define every stored procedure in my Package in order to use the REF CURSOR variable to return the result set to my objects?

Thanks,
Dan

P.S.  How do you get syntax coloring to work when you post code here?
        Yeah, I'm a newb.

nermin replied on Wednesday, March 19, 2008

REF CURSOR variable/type has to e declared outside of the SP.  Therefore yes, you have to place the stored procedure in the same package as where you define the OUT CURSOR.

 

Nermin

 

From: dorlett [mailto:cslanet@lhotka.net]
Sent: Wednesday, March 19, 2008 11:40 AM
To: Nermin Dibek
Subject: [CSLA .NET] Oracle REF CURSOR and Procedures

 

This may be too basic a question, if so please forgive...

I'm testing switching from using SQL Server database to Oracle.  By following tips from other posts here, I've successfully tested creating a Package defining a REF CURSOR variable and a Procedure that uses the REF CURSOR variable as an OUT parameter, and successfully retrieved data in my test object using:

    private void ExecuteFetch(OracleConnection cn, FilterCriteria criteria)
    {
        using (OracleCommand cm = cn.CreateCommand())
        {
            cm.CommandType = CommandType.StoredProcedure;
            cm.CommandText = "PACKAGE1.ship_test_select";
            OracleParameter p_refcursor = new OracleParameter("outCursor",OracleType.Cursor);
            p_refcursor.Direction = ParameterDirection.Output;
            cm.Parameters.Add(p_refcursor);

            using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
            {
                while (dr.Read())
                    this.Add(Ship_TestReadOnlyChild.GetShip_TestReadOnlyChild(dr));
                dr.Close();
            }
           
        }//using
    }

I have too many questions, but am I correct in thinking I will need to define every stored procedure in my Package in order to use the REF CURSOR variable to return the result set to my objects?

Thanks,
Dan

P.S.  How do you get syntax coloring to work when you post code here?
        Yeah, I'm a newb.


Copyright (c) Marimer LLC