SQL$HELP_OLD72.HLB  —  External Routines
    User-defined functions allow you to execute subprograms written
    either in 3GL host languages (such as C or SQL Module language)
    or in the SQL procedural language. There are two classes of user-
    defined functions:

    o  The external function feature consists of several discrete
       pieces: the routine definition, the executable, and the
       invocation. You define a function that points to the
       executable form of the routine. You code, compile, and link
       the routine written in a 3GL language.

       See CREATE Routine and CREATE MODULE for information on
       creating external routines.

    o  The SQL function feature consists a module definition
       containing the function definition. Such SQL functions can
       include any SQL procedural language features (except those
       that change the transaction state: SET TRANSACTION, START
       TRANSACTION, COMMIT and ROLLBACK) and can invoke other
       functions, call procedures (using the CALL statement) which
       in turn can activate other user-defined routines.

       See CREATE MODULE for information on creating modules and
       functions in SQL.

    The function definitions reside in the database like any other
    schema object, such as a table or view. Use the SHOW FUNCTION
    statement to display the names of user-defined functions. See
    SHOW for more information and examples.

    Finally, you refer to the routine within an SQL statement for
    automatic invocation by the SQL interface.

    The following diagram shows how to invoke a user-defined
    function:

  function-invocation =

  --> <function-name> --> ( -+-----------------+-> ) -->
                             ++-> value-expr -++
                              +-> DEFAULT ----+
                              +------ , <-----+

    You invoke a user-defined function from anywhere you can specify
    a value expression. Some of the locations from which you can
    invoke an external function are:

    o  A column using a COMPUTED BY or AUTOMATIC AS value expression
       clause

    o  A CHECK clause in a table constraint, column constraint, or
       domain constraint

    o  A select expression in a view definition or cursor declaration

    o  On the right-hand side of a set-assignment-statement of a
       compound statement or of the SET clause of an UPDATE statement

    o  A select list or where clause

    o  A DEFAULT value expression clause for a domain, column or
       parameter
Close Help