getNumResultCols, any better ways?

getNumResultCols, any better ways?

Post by James Che » Sat, 15 Mar 1997 04:00:00

Hi Oracle/OCI gurus,

What's the best way to know NumResultCols of a query in OCI ?

One naive way is to use the following sequential loop:

  BOOL bError = FALSE;
  int  nNumResultCols = 0;

  for (int pos = 1; pos < MAX_NUMBER_OF_ITEMS; pos++) {
    rc = odescr(&cda, pos, ...);
    if (rc == 1007) break;
    if (rc < 0) {
      // handle error
      bError = TRUE;
  if (!bError) {
    nNumResultCols = pos - 1;

The drawback of the above loop is the inefficiency. odescr() OCI call
goes to the server every time you call it. If there are large # of
columns in a query, it would be really inefficient.

One way I can think of to improve the efficiency is to call
odescr() with a 'pos' picked in binary-searching fashion.

Is there a better way to do it ?


James Chen,     at Interweave Software, Inc.