Enterprise Edition Home | Express Edition Home | Previous Page | Next Page   SQL Statements >

CREATE FUNCTION FROM

Use the CREATE FUNCTION FROM statement to access a user-defined function whose CREATE FUNCTION statement resides in a separate file.

Only Dynamic Server supports this statement, which is an extension to the ANSI/ISO standard for SQL. Use this statement with ESQL/C.

Syntax

Read syntax diagramSkip visual syntax diagram>>-CREATE FUNCTION FROM--+-'file'---+--------------------------><
                         '-file_var-'
 
Element Description Restrictions Syntax
file Path and filename of a file that contains the full CREATE FUNCTION statement text. Default pathname is current directory. Must exist and contain exactly one CREATE FUNCTION statement Must conform to operating-system rules.
file_var Variable storing value of file Same as for file Language specific

Usage

Functions written in the C or Java language are called external functions. When the IFX_EXTEND_ROLE configuration parameter is set to ON, only users who have been granted the built-in EXTEND role can create external functions.

An ESQL/C program cannot directly create a user-defined function. That is, it cannot contain the CREATE FUNCTION statement.

To create these functions within an ESQL/C program
  1. Create a source file with the CREATE FUNCTION statement.
  2. Use the CREATE FUNCTION FROM statement to send the contents of this source file to the database server for execution.

    The file that you specify in the file parameter can contain only one CREATE FUNCTION statement.

For example, suppose that the following CREATE FUNCTION statement is in a separate file, called del_ord.sql:

CREATE FUNCTION delete_order( p_order_num int) RETURNING int, int;
   DEFINE item_count int;
   SELECT count(*) INTO item_count FROM items
      WHERE order_num = p_order_num;
   DELETE FROM orders WHERE order_num = p_order_num;
   RETURN p_order_num, item_count;
END FUNCTION; 

In the ESQL/C program, you can access the delete_order( ) SPL function with the following CREATE FUNCTION FROM statement:

EXEC SQL create function from 'del_ord.sql';

If you are not sure whether the UDR in the file is a user-defined function or a user-defined procedure, use the CREATE ROUTINE FROM statement.

The filename that you provide is relative. If you provide a simple filename with no pathname (as in the preceding example), the client application looks for the file in the current directory.

Important:
The ESQL/C preprocessor does not process the contents of the file that you specify. It only sends the contents to the database server for execution. Therefore, there is no syntactic check that the file that you specify in CREATE FUNCTION FROM actually contains a CREATE FUNCTION statement. To improve readability of the code, however, it is recommended that you match these two statements.

Related Information

Related statements: CREATE FUNCTION, CREATE PROCEDURE, CREATE PROCEDURE FROM, and CREATE ROUTINE FROM

Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]