Search code examples
c#stored-proceduresoracle-manageddataaccessref-cursorodp.net-managed

C# - Oracle Stored Procedure return RefCursor without rows


My Stored Procedure call does return 7 rows, but not when I call it through Oracle Managed data access.

Code :

    string _connectionString = 
        String.Format("Data Source={0};User Id={1};Password={2};",
            tbDataSource.Text, tbUser.Text, tbPassword.Text);


    using (OracleConnection conn = new OracleConnection(_connectionString)){
        using (OracleCommand cmd = new OracleCommand()){
            cmd.CommandText = "XXCOOT_QUERIES.getWarehouses";
            cmd.CommandType = CommandType.StoredProcedure;

            // Parameters
            OracleParameter p1 = new OracleParameter();
            p1.ParameterName = "inumActivityId";
            p1.OracleDbType = OracleDbType.Varchar2;
            p1.Direction = ParameterDirection.Input;
            p1.Size = 10;
            p1.Value = 108;
            cmd.Parameters.Add(p1);

            OracleParameter cursor = new OracleParameter();
            cursor.ParameterName = "ocursWarehouses";
            cursor.OracleDbType = OracleDbType.RefCursor;
            cursor.Direction = ParameterDirection.Output;
            cmd.Parameters.Add(cursor);

            OracleParameter p2 = new OracleParameter();
            p2.ParameterName = "ostrErrCode";
            p2.OracleDbType = OracleDbType.Varchar2;
            p2.Direction = ParameterDirection.Output;
            p2.Size = 2000;
            cmd.Parameters.Add(p2);

            DataTable dt = new DataTable();
            OracleDataReader reader = null;

            conn.Open();
            cmd.Connection = conn;

            using (reader = cmd.ExecuteReader()){
                dt.Load(reader);
                this.tbResult.Text = "Rows Count : " +
                    dt.Rows.Count.ToString(); // Returns: "Rows Count : 0"

                this.dataGridView1.DataSource = dt.DefaultView;
                // Returns : " | Column1 | Column2 | "
                //             |-------- | --------|
            }
        }
    }

Stored Procedure

PROCEDURE getWarehouses
     ( inumActivityId   in   varchar2
     , ocursWarehouses  out  grefCursorType
     , ostrErrCode      out  varchar2
 )
IS
    lextorg varchar2(150);
BEGIN
    FND_CLIENT_INFO.Set_Org_Context(inumActivityId);
   lextorg := null;

   SELECT b.GENERIC_EXTERNAL_ORGANIZATION
   INTO   lextorg
   FROM   HR_ORGANIZATION_INFORMATION a
   ,      HR_ORGANIZATION_INFORMATIO_DFV b
   WHERE  a.organization_id = to_number(inumActivityId)
   AND    a.ORG_INFORMATION_CONTEXT = 'Operating Unit Information'
   AND    a.rowid = b.rowid;

IF lextorg is null THEN

    OPEN ocursWarehouses FOR
        SELECT ood.organization_code  organization_code
         ,      ood.organization_name  name
         FROM   org_organization_definitions  ood
         ,      mtl_parameters                mp
         ,      mtl_parameters_dfv            mp_dfv
         WHERE ood.operating_unit = to_number(inumActivityId)
         AND   sysdate <= nvl(disable_date,sysdate)
         AND   ood.organization_id = mp.organization_id
         AND   mp.rowid = mp_dfv.row_id
         AND   upper(mp_dfv.warehouse_type) in ('INTERNAL','EXTERNAL')
         ORDER by organization_name;

ELSE

    OPEN ocursWarehouses FOR
        SELECT ood.organization_code  organization_code
        ,      ood.organization_name  name
        FROM   org_organization_definitions  ood
        ,      mtl_parameters                mp
        ,      mtl_parameters_dfv            mp_dfv
        WHERE -ood.operating_unit = to_number(inumActivityId)
        AND sysdate <= nvl(disable_date,sysdate)
        AND   ood.organization_id = mp.organization_id
        AND   mp.rowid = mp_dfv.row_id
        AND   upper(mp_dfv.warehouse_type) in ('INTERNAL','EXTERNAL')
        ORDER by organization_name;
END/

At execution : No warnings, no errors (all parameters are valids)

My problem : Any rows are returned (instead of the 7 expected rows) but I retrieve the schema (column names are corrects).


Environment :

  • Windows x64
  • .NET Framework : 4.0
  • Oracle Client installed (v11.2) but not necessary
  • Oracle Data Provider .NET : Oracle.ManagedDataAccess (v121.1.2)

Solution

  • Well, after months and months, I've found the cause of my problem :

    My Stored Procedure use view(s) in its FROM clause. This (these) view(s) use the LOB datatype (I found this problem thanks to a Oracle returned error).