Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: get NumResultCols, any better way?
James Chen <james_at_iweave.com> wrote in article <3329B4EA.99E_at_iweave.com>...
> 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;
> break;
> }
> }
> 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.
i don't see the problem:
if you know the sql, then you already know the number (and type) of the
columns.
if the sql is 'dynamic' (ie: read from a file) you must odescr every column
anyway (to get the datatypes).
> One way I can think of to improve the efficiency is to call
> odescr() with a 'pos' picked in binary-searching fashion.
good idea.
why do you want to know the number of columns at this stage?
if you need it to setup an array of 'odescr' structures
(malloc(nNumResultCols * sizeof(odescr-structure)) you could do it with
realloc or use a list or a Vector/Array class.
-- At Home: gem_at_wirehub.nl At Work: gert.rijs_at_corp.ah.nlReceived on Sat Mar 15 1997 - 00:00:00 CST