INFORMIX
Extending INFORMIX-Universal Server: User-Defined Routines
Chapter 4: Debugging User-Defined Routines
Home Contents Index Master Index New Book

Invoking a Routine

This section describes the following methods that you can use to invoke a routine:

Invoking a Function with the EXECUTE statement

You can use the EXECUTE statement with the FUNCTION keyword to execute a function from one of the following:

For example, suppose result is a function variable of type BOOLEAN. The following EXECUTE statement invokes the equal() function:

The INTO clause must always be present when you invoke a function using an EXECUTE statement.

Important: You cannot use the EXECUTE statement to invoke a function that has an OUT parameter.
As another example, suppose you create the following type hierarchy and functions:

The following EXECUTE 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 function invoked with the EXECUTE statement, ensure that you enclose the query in another set of parentheses.

Invoking a Procedure with the EXECUTE statement

You can use the EXECUTE statement with the PROCEDURE keyword to execute a procedure from within an SPL or ESQL/C program or DB-Access. The following EXECUTE statement invokes the log_compare() function:

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

Invoking a Function with the CALL Statement

You can use the CALL statement to invoke a function from within an SPL program only. The following statement invokes the equal() function:

When you invoke a function with the CALL statement, you must include a RETURNING clause and the name of the value or values that the function returns.

You cannot use the CALL statement to invoke a function that has an OUT parameter.

You cannot execute the CALL statement from within an ESQL/C program or the DB-Access utility.

Invoking a Procedure with the CALL Statement

You can use the CALL statement to invoke a procedure from within an SPL program only. The following CALL statement invokes the log_compare() procedure:

A RETURNING clause is never present when you invoke a procedure with the CALL statement because a procedure does not return a value.

Invoking a Function in an Expression

You can invoke a function in an expression either explicitly or implicitly. An external procedure cannot be used in an expression because an external procedure does not return a value. This section describes how you can invoke functions explicitly and implicitly in an expression. The examples in the following sections use the new_type1 and new_type2 distinct types and the tab_1 table. Figure 4-1 shows the syntax that creates the distinct types and table.

Figure 4-1

Explicitly Invoking a Function in an Expression

You can invoke a function in an expression when the function returns a single value. Suppose an equal() function exists to evaluate the equality of new_type1 and new_type2 values. The following query invokes the appropriate equal() function in the WHERE clause of the SELECT statement:

Implicitly 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 new_type1 and returns a Boolean. If the equal operator (=) is used for comparisons between col_1 and col_2, 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:

Implicitly Invoking a Function for Casting

Suppose you create the following external function to cast a value of newtype2 to newtype1:

Suppose also that you register the function as an implicit cast, as follows:

The following query automatically invokes the cast to convert new_type2 values to newtype1 before it invokes the equal() function:

The previous query is equivalent to the following statement:




Extending INFORMIX-Universal Server: User-Defined Routines, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.