informix
Extending Informix Dynamic Server 2000
Running a User-Defined Routine

Invoking a User-Defined Routine

This section describes the ways that you can invoke a user-defined routine:

Invoking a UDR in an SQL Statement

You can invoke a user-defined routine from within an SQL statement in the following ways:

Invoking a UDR with an EXECUTE Statement

For details about the syntax of the EXECUTE FUNCTION and EXECUTE PROCEDURE statements, see the Informix Guide to SQL: Syntax. For more information about creating UDRs, refer to Chapter 4, Developing a User-Defined Routine.

Invoking a Function

Suppose result is a function variable of type INTEGER. The following example shows how to register and invoke a C user-defined function called nFact() that returns N-factorial (n!):

The INTO clause must always be present when you invoke a user-defined function with the EXECUTE FUNCTION statement.

Important: You cannot use the EXECUTE FUNCTION statement to invoke a user-defined function that contains an OUT parameter. Using a SELECT Statement in a Function Argument

As another example, suppose you create the following type hierarchy and functions:

The following EXECUTE FUNCTION statement invokes the func1() function, which has an argument that is a query that returns a row type:

Important: When you use a query for the argument of a user-defined function invoked with the EXECUTE FUNCTION statement, you must enclose the query in another set of parentheses.

Invoking a Procedure

The following EXECUTE PROCEDURE statement invokes the log_compare() function:

The INTO clause is never present when you invoke a user-defined procedure with the EXECUTE PROCEDURE statement because a procedure does not return a value.

Invoking a User-Defined Function in an Expression

You can invoke a user-defined function in an expression in the select list of a SELECT statement, or in the WHERE clause of an INSERT, SELECT, UPDATE, or DELETE statement.

For example, with the factorial function described in Invoking a Function, you might write the following SELECT statement:

Invoking a Function That Is Bound to an Operator

Functions that are bound to specific operators get invoked automatically without explicit invocation. Suppose an equal() function exists that takes two arguments of type1 and returns a Boolean. If the equal operator (=) is used for comparisons between two columns, col_1 and col_2, that are of type1 the equal() function gets invoked automatically. For example, the following query implicitly invokes the appropriate equal() function to evaluate the WHERE clause:

The preceding query evaluates as though it had been specified as follows:

Invoking a UDR in an SPL Routine

You use the CALL statement only to invoke a UDR from within an SPL program. You can use CALL to invoke both user-defined functions and user-defined procedures, as follows:


Extending Informix Dynamic Server 2000, Version 9.2
Copyright © 1999, Informix Software, Inc. All rights reserved