View Single Post

   
  #2 (permalink)  
Old 02-27-2008, 04:11 AM
Knut Stolze
 
Posts: n/a
Default Re: using nextval in external udf

pfa wrote:

> I have a udf which returns a table. I was hoping to access the NEXTVAL
> from a sequence to affect the logic flow and consequently the return
> result. I'm using a LANGUAGE C type function.
>
> Here's the fetch snippet
>
> case SQLUDF_TF_FETCH:
> /* fetch next row */
> {
> char * nextid = myrecids++;
> char * ptr;
> --pScratArea->recids_len;
> if (pScratArea->recids_len < 1)
> {
> /* SQLUDF_STATE is part of SQLUDF_TRAIL_ARGS_ALL */
> strcpy(outRecid, "");
> strcpy(SQLUDF_STATE, "02000");
> break;
> }
> // look for AM and terminate nextid
> for (ptr = nextid; *ptr != '\376'; ++ptr) --pScratArea->recids_len;
> *(ptr) = '\0';
> myrecids = ptr + 1;
>
> // copy current null terminated ptr to outRecid (return arg)
> strcpy(outRecid, nextid);
> }
>
> *recidNullInd = 0;
> /* next row of data */
> pScratArea->file_pos++;
> break;
>
>
> What I'm hoping to do is use the result of a NEXTVAL call to cross
> check against a counter in my scratch pad such that multiple process
> can be feeding off this function table each row from the function table
> would only be processed once.


I still don't quite understand your scenario, but you could use embedded SQL
and simply query the sequence that way. You have to register the UDF with
READS SQL DATA, however.

--
Knut Stolze
Information Integration Development
IBM Germany / University of Jena
Reply With Quote