Re: Help with how to use a user defined function in Universal Server
Posted in 1998
>Say I have a user defined function like
>
>create function f() returning int;> let rid = select rowid from .....;
> return rid;
>end function;
>
>Ok, the function does some sort of query, and returns a row id for
>the row that is found.
>
>Now, I'd like to use it like so maybe:
>
> select * from tbl where rowid = f();>
>This isn't good because f is invoked for each row in tbl.
>So, how to do it.
>
>The SPL would be something like
>
> execute function f() into rid;
> select * from tbl where rowid=rid;>
>But is there no magic SQL select syntax that would get this done in
>one statement?
>
>Obviously, I'm pretty new to SQL3 and the idea of extended user types
>and functions. So far, I am not finding the Informix manuals
>to be particularly well written or organized, so any quality book references
>would be very much appreciated as well.
>
>Thanks.
>
>============================================================
Try
select * from tbl where rowid = ( select f() from systables where tabid = 1);
This will cause the f() function to only be executed once.
Madison Pruet