2 Replies Latest reply: Jul 18, 2013 2:04 PM by Chalfont St. Giles RSS

    Vc++ how to read column header of cursor


      How to fetch the Column name or header of the stored procedure which is using a cursor as the output.

      P_out  out sys_refcursor

      need to read the column name of this output.

      I am using Vc++ code to reterive the data, in Vc++ how to read column header of cursor

        • 1. Re: Vc++ how to read column header of cursor
          gdarling - oracle

          You haven't provided much detail to go on.  How are you reading data from the ref cursor? Do you already have a reader from it?


          Maybe this helps.






          create or replace procedure proc1 (v1 out sys_refcursor) as


          open v1 for select * from emp;





          using System;

          using System.Data;

          using Oracle.DataAccess.Client;

          using Oracle.DataAccess.Types;


          public class RefCur


              public static void Main()


                  using (OracleConnection con = new OracleConnection("user id=scott;password=tiger;data source=orcl"))



                      using (OracleCommand cmd = new OracleCommand("proc1", con))


                          cmd.CommandType = CommandType.StoredProcedure;

                          cmd.Parameters.Add(new OracleParameter("v1", OracleDbType.RefCursor, ParameterDirection.Output));



                          using (OracleDataReader reader = ((OracleRefCursor)cmd.Parameters[0].Value).GetDataReader())


                              for (int i=0;i<reader.FieldCount;i++)







          • 2. Re: Vc++ how to read column header of cursor
            Chalfont St. Giles



            I was going to ask whether you've landed in the wrong forum as you mention you are using VC++ and this is the Oracle Data Provider for .NET (ODP.NET) forum; however, it seems the Oracle C++ Call Interface (OCCI) forum has been archived with the new system. I'm not sure where one would post questions related to C++/OCCI at this time (maybe the OCI forum?).


            So, if you are using OCCI rather than C#/ODP.NET you would get the metadata from the resultset and interate over the columns to get the names, etc.


            As a quick and dirty sample of what I mean:

            // get the ref cursor as an occi resultset
            rs = stmt->getCursor(1);
            // get the column list meta data
            vector<MetaData> ColList = rs->getColumnListMetaData();
            // iterate over the column list meta data
            for (int i = 0; i < ColList.size(); i++)
              // get the meta data for this column
              MetaData ColData = ColList[i];
              // display the column name
              cout << "Column Name: " << (ColData.getString(MetaData::ATTR_NAME)) << endl;


            Of course if you are not using OCCI disregard the above!