informix
Informix Guide to SQL: Syntax
SQL Statements

EXECUTE PROCEDURE

Use the EXECUTE PROCEDURE statement to execute a user-defined procedure.

Syntax

Element Purpose Restrictions Syntax
function Name of the SPL function to execute The function must exist. Database Object Name, p. 4-50
output_var Host variable or program variable that receives the value returned by a user-defined function If you issue this statement within a CREATE TRIGGER statement, the output_var must be column names within the triggering table or another table. Name must conform to language-specific rules for variable names. For the syntax of SPL variables, see Identifier, p. 4-205. For the syntax of column names, see Identifier, p. 4-205.
procedure Name of the user-defined procedure to execute The procedure must exist. Database Object Name, p. 4-50
SPL_var Variable created with the DEFINE statement that contains the name of an SPL routine to be executed The SPL variable must be CHAR, VARCHAR, NCHAR, or NVARCHAR data type. The name assigned to SPL_var must be non-null and the name of an existing SPL routine. Identifier, p.4-205

Usage

The EXECUTE PROCEDURE statement invokes the named user-defined procedure and specifies its arguments.

In Dynamic Server, for backward compatibility, you can use the EXECUTE PROCEDURE statement to execute an SPL function that was created with the CREATE PROCEDURE statement.

In Enterprise Decision Server, use the EXECUTE PROCEDURE statement to execute any SPL routine. Enterprise Decision Server does not support the EXECUTE FUNCTION statement.

In ESQL/C, if the EXECUTE PROCEDURE statement returns more than one row, it must be enclosed within an SPL FOREACH loop or accessed through a cursor.

Using the INTO Clause

Use the INTO clause to specify where to store the values that the SPL function returns.

If an SPL function returns more than one value, the values are returned into the list of variables in the order in which you specify them. If an SPL function returns more than one row or a collection data type, you must access the rows or collection elements with a cursor.

You cannot prepare an EXECUTE PROCEDURE statement that has an INTO clause. For more information, see Alternatives to Preparing an EXECUTE FUNCTION...INTO Statement.

Dynamic Routine-Name Specification of SPL Procedures

Dynamic routine-name specification simplifies the writing of an SPL routine that calls another SPL routine whose name is not known until runtime. To specify the name of an SPL routine in the EXECUTE PROCEDURE statement, instead of listing the explicit name of an SPL routine, you can use an SPL variable to hold the routine name.

If the SPL variable names an SPL routine that returns a value (an SPL function), include the INTO clause of EXECUTE PROCEDURE to specify a receiving variable (or variables) to hold the value (or values) that the SPL function returns.

For more information on how to execute SPL procedures dynamically, see the Informix Guide to SQL: Tutorial.

Causes of Errors

The EXECUTE PROCEDURE statement returns an error under the following conditions:

SQLJ Driver Built-In Procedures

Use the SQLJ Driver built-in procedures for one of the following tasks:

The SQLJ built-in procedures are stored in the sysprocedures catalog table. They are grouped under the sqlj schema.

Tip: For any Java static method, the first built-in procedure that you execute must be the install_jar() procedure. You must install the jar file before you can create a UDR or map a user-defined data type to a Java type. Similarly, you cannot use any of the other SQLJ built-in procedures until you have used install_jar().

sqlj.install_jar

Use the install_jar() procedure to install a Java jar file in the current database and assign it a jar identifier.

Element Purpose Restrictions Syntax
deploy Integer that causes the procedure to search for deployment descriptor files in the jar file None. Literal Number,
p.
4-237
jar_file URL of the jar file that contains the UDR written in Java The maximum length of the URL is 255 bytes. Quoted String,
p.
4-260

For example, consider a Java class Chemistry which contains the following static method explosiveReaction():

Suppose that the Chemistry class resides in the following jar file on the server computer:

You can install all classes in the Courses.jar jar file in the current database with the following call to the install_jar() procedure:

The install_jar() procedure assigns the jar ID, course_jar, to the Courses.jar file that it has installed in the current database.

After you define jar ID in the database, you can use that jar ID when you create and execute a UDR written in Java.

Using Deployment Descriptor Files

When you specify a nonzero number for the third argument, the database server searches through any included deployment descriptor files. For example, you might want to included descriptor files that include SQL statements to register and grant privileges on UDRs in the jar file.

sqlj.replace_jar

Use the replace_jar() procedure to replace a previously installed jar file with a new version. When you use this syntax, you provide only the new jar file and assign it to the jar ID for which you want to replace the file.

Element Purpose Restrictions Syntax
jar_file URL of the jar file that contains the UDR written in Java The maximum length of the URL is 255 bytes. Quoted String,
p.
4-260

If you attempt to replace a jar file that is referenced by one or more UDRs, the database server generates an error. You must drop the referencing UDRs before replacing the jar file.

For example, the following call replaces the Courses.jar file, which had previously been installed for the course_jar identifier, with the Subjects.jar file:

Before you replace the Course.jar file, you must drop the user-defined function sql_explosive_reaction() with the DROP FUNCTION (or DROP ROUTINE) statement.

sqlj.remove_jar

Use the remove_jar() procedure to remove a previously installed jar file from the current database.

Element Purpose Restrictions Syntax
deploy Integer that causes the procedure to search for deployment descriptor files in the jar file None. Literal Number,
p.
4-237

If you attempt to remove a jar file that is referenced by one or more UDRs, the database server generates an error. You must drop the referencing UDRs before replacing the jar file.

For example, the following SQL statements remove the jar file associated with the course_jar jar id:

Using Deployment Descriptor Files

When you specify a nonzero number for the second argument, the database server searches through any included deployment descriptor files. For example, you might want to include descriptor files that include SQL statements that revoke privileges on the UDRs in the associated jar file and to drop them from the database.

sqlj.alter_java_path

Use the alter_java_path() procedure to specify the jar-file path to use when the routine manager resolves related Java classes for the jar file of a UDR written in Java.

Element Purpose Restrictions Syntax
class_id Name of the Java class that contains the method to implement the UDR The Java class must exist in the jar file that jar_id identifies. The fully qualified identifier of package_id.class_id must not exceed 255 bytes. Name must conform to language-specific rules for Java identifiers.
package_id Name of the package that contains the Java class The fully qualified identifier of package_id.class_id must not exceed 255 bytes. Name must conform to language-specific rules for Java identifiers.

The jar IDs that you specify, (the jar ID for which you are altering the jar-file path and the resolution jar ID) must have been installed with the sqlj.install_jar procedure.

When you invoke a UDR written in Java, the routine manager attempts to load the Java class in which the UDR resides. At this time, it must resolve the references that this Java class makes to other Java classes. The three types of such class references are:

  1. References to Java classes that the JVPCLASSPATH configuration parameter specifies (such as Java system classes like java.util.Vector)
  2. References to classes which are in the same jar file as the UDR
  3. References to classes which are outside the jar file that contains the UDR

The routine manager implicitly resolves classes of type 1 and 2 in the preceding list. However, to resolve type 3 references, the routine manager examines all the jar files in the jar-file path that the latest call to alter_java_path() has specified. The routine manager throws an exception if it cannot resolve a class reference.

The routine manager checks the jar-file path for class references after it performs the implicit type 1 and type 2 resolutions. If you want a Java class to be loaded from the jar file that the jar-file path specifies, make sure the Java class is not present in the JVPCLASSPATH configuration parameter. Otherwise, the system loader picks up that Java class first, which might result in a different class being loaded than what you expect.

Suppose that the install_jar() procedure and the CREATE FUNCTION statement have been executed as described in preceding sections. The following SQL statement invokes sql_explosive_reaction() function in the course_jar jar file:

The routine manager attempts to load the class Chemistry. It uses the path that the call to alter_java_path() specifies to resolve any class references. Therefore, it checks the classes that are in the professor package of the jar file that prof_jar identifies.

sqlj.setUDTExtName

Use the setUDTExtName() procedure to define the mapping between a user-defined data type and a Java class.

Element Purpose Restrictions Syntax
class_id Name of the Java class that contains the Java data type The fully qualified identifier of package_id.class_id must not exceed 255 bytes. Name must conform to language-specific rules for Java identifiers.
data_type Name of user-defined type for which you want to create a mapping You must have registered the type of one of the following statements:
  • CREATE DISTINCT TYPE
  • CREATE OPAQUE TYPE
  • CREATE ROW TYPE The name must not exceed 255 bytes.
  • Identifier, p. 4-205
    package_id Name of the package that contains the Java class The fully qualified identifier of package_id.class_id must not exceed 255 bytes. Name must conform to language-specific rules for Java identifiers.

    To look up the Java class for a user-defined data type, the database server searches in the jar-file path, which the alter_java_path() procedure has specified. For more information on the jar-file path, seesqlj.alter_java_path.

    On the client side, the driver looks into the CLASSPATH path on the client environment before it asks the database server for the name of the Java class.

    The setUDTExtName procedure is an extension to the SQLJ:SQL Routines using the Java Programming Language specification.

    sqlj.unsetUDTExtName

    Use the remove_jar() procedure to remove the mapping from a user-defined data type to a Java class.

    Element Purpose Restrictions Syntax
    data_type Name of user-defined type for which you want to remove the mapping The data type must exist. Identifier, p. 4-205

    This procedure removes the SQL-to-Java mapping, and consequently removes any cached copy of the Java class from database server shared memory.

    The unsetUDTExtName procedure is an extension to the SQLJ:SQL Routines using the Java Programming Language specification.

    Related Information

    Related statements: CREATE FUNCTION, CREATE PROCEDURE, EXECUTE FUNCTION, GRANT, CALL, FOREACH, and LET


    Informix Guide to SQL: Syntax, Version 9.2
    Copyright © 1999, Informix Software, Inc. All rights reserved