ALTER FUNCTION (external)

The ALTER FUNCTION statement changes the description of a user-defined external scalar function or external table function at the current server.

Invocation

This statement can be embedded in an application program or issued interactively. It is an executable statement that can be dynamically prepared only if DYNAMICRULES run behavior is implicitly or explicitly specified.

Authorization

The privilege set defined below must include at least one of the following:

  • Ownership of the function
  • The ALTERIN privilege on the schema
  • SYSADM or SYSCTRL authority
  • Start of changeSystem DBADMEnd of change

The authorization ID that matches the schema name implicitly has the ALTERIN privilege on the schema.

Start of changeIf the authorization ID that is used to alter the function has installation SYSADM authority, the function is identified as system-defined function when the function definition is reevaluated.End of change

Start of changeAt least one of the following privileges is required if the SECURED option is specified or if the function is currently secured and the NOT SECURED option is specified:
  • SECADM authority
  • CREATE_SECURE_OBJECT privilege
End of change

For external scalar functions, when LANGUAGE is JAVA and a jar-name is specified in the EXTERNAL NAME clause, the privilege set must include USAGE on the JAR file.

Privilege set: If the statement is embedded in an application program, the privilege set is the privileges that are held by the owner of the package.
If the statement is dynamically prepared, the privilege set is the set of privileges that are held by the SQL authorization IDs of the process. The specified routine name can include a schema name (a qualifier). However, if the schema name is not the same as one of these SQL authorization IDs, one of the following conditions must be met:
  • The privilege set includes SYSADM authority
  • The privilege set includes SYSCTRL authority
  • The SQL authorization ID of the process has the ALTERIN privilege on the schema

If the environment in which the function is to be run is being changed, the authorization ID must have authority to use the WLM environment specified. The required authorization is obtained from an external security product, such as RACF®.

Start of change

Syntax

>>-ALTER-------------------------------------------------------->

>--+-FUNCTION--function-name--+----------------------------------+-+-->
   |                          |    .-,----------------------.    | |   
   |                          |    V                        |    | |   
   |                          '-(----+--------------------+-+--)-' |   
   |                                 '-| parameter-type |-'        |   
   |                                                               |   
   |                                                               |   
   '-SPECIFIC FUNCTION--specific-name------------------------------'   

>--| option-list |---------------------------------------------><

parameter-type:

>>---| data-type |--+----------------+-------------------------><
                    |            (1) |     
                    '-AS LOCATOR-----'     

Notes:
  1. AS LOCATOR can be specified only for a LOB data type or a distinct type based on a LOB data type.

data-type:

>>-+-built-in-type------+--------------------------------------><
   '-distinct-type-name-'   

built-in-type:

>>-+-+-SMALLINT----+-------------------------------------------------------------------------------------------------+-><
   | +-+-INTEGER-+-+                                                                                                 |   
   | | '-INT-----' |                                                                                                 |   
   | '-BIGINT------'                                                                                                 |   
   |              .-(5,0)--------------------.                                                                       |   
   +-+-DECIMAL-+--+--------------------------+-----------------------------------------------------------------------+   
   | +-DEC-----+  '-(integer-+-----------+-)-'                                                                       |   
   | '-NUMERIC-'             '-, integer-'                                                                           |   
   |          .-(53)------.                                                                                          |   
   +-+-FLOAT--+-----------+--+---------------------------------------------------------------------------------------+   
   | |        '-(integer)-'  |                                                                                       |   
   | +-REAL------------------+                                                                                       |   
   | |         .-PRECISION-. |                                                                                       |   
   | '-DOUBLE--+-----------+-'                                                                                       |   
   |           .-(34)-.                                                                                              |   
   +-DECFLOAT--+------+----------------------------------------------------------------------------------------------+   
   |           '-(16)-'                                                                                              |   
   |                    .-(1)-------.                                                                                |   
   +-+-+-+-CHARACTER-+--+-----------+----------+----+--------------------+--+----------------------+---------------+-+   
   | | | '-CHAR------'  '-(integer)-'          |    '-CCSID--+-ASCII---+-'  '-FOR--+-SBCS--+--DATA-'               | |   
   | | '-+-+-CHARACTER-+--VARYING-+--(integer)-'             +-EBCDIC--+           +-MIXED-+                       | |   
   | |   | '-CHAR------'          |                          '-UNICODE-'           '-BIT---'                       | |   
   | |   '-VARCHAR----------------'                                                                                | |   
   | |                                  .-(1M)-------------.                                                       | |   
   | '-+-+-CHARACTER-+--LARGE OBJECT-+--+------------------+----+--------------------+--+----------------------+---' |   
   |   | '-CHAR------'               |  '-(integer-+---+-)-'    '-CCSID--+-ASCII---+-'  '-FOR--+-SBCS--+--DATA-'     |   
   |   '-CLOB------------------------'             +-K-+                 +-EBCDIC--+           '-MIXED-'             |   
   |                                               +-M-+                 '-UNICODE-'                                 |   
   |                                               '-G-'                                                             |   
   |            .-(1)-------.                                                                                        |   
   +-+-GRAPHIC--+-----------+-------+--+--------------------+--------------------------------------------------------+   
   | |          '-(integer)-'       |  '-CCSID--+-ASCII---+-'                                                        |   
   | +-VARGRAPHIC--(--integer--)----+           +-EBCDIC--+                                                          |   
   | |         .-(1M)-------------. |           '-UNICODE-'                                                          |   
   | '-DBCLOB--+------------------+-'                                                                                |   
   |           '-(integer-+---+-)-'                                                                                  |   
   |                      +-K-+                                                                                      |   
   |                      +-M-+                                                                                      |   
   |                      '-G-'                                                                                      |   
   |           .-(1)-------.                                                                                         |   
   +-+-BINARY--+-----------+-------------------------+---------------------------------------------------------------+   
   | |         '-(integer)-'                         |                                                               |   
   | +-+-BINARY VARYING-+-(integer)------------------+                                                               |   
   | | '-VARBINARY------'                            |                                                               |   
   | |                          .-(1M)-------------. |                                                               |   
   | '-+-BINARY LARGE OBJECT-+--+------------------+-'                                                               |   
   |   '-BLOB----------------'  '-(integer-+---+-)-'                                                                 |   
   |                                       +-K-+                                                                     |   
   |                                       +-M-+                                                                     |   
   |                                       '-G-'                                                                     |   
   +-+-DATE------------------------------------------------+---------------------------------------------------------+   
   | +-TIME------------------------------------------------+                                                         |   
   | |            .-(--6--)-------.  .-WITHOUT TIME ZONE-. |                                                         |   
   | '-TIMESTAMP--+---------------+--+-------------------+-'                                                         |   
   |              '-(--integer--)-'  '-WITH TIME ZONE----'                                                           |   
   '-ROWID-----------------------------------------------------------------------------------------------------------'   

option-list: (Specify options in any order. Specify at least one option. Do not specify the same option more than once.)

                                          (1)     
>>-EXTERNAL NAME--+-external-program-name-----+----------------->
                  '-identifier----------------'   

>--LANGUAGE--+-ASSEMBLE-----+----------------------------------->
             +-C------------+   
             +-COBOL--------+   
             |      (2) (3) |   
             +-JAVA---------+   
             '-PLI----------'   

>--PARAMETER STYLE--+-SQL----------+--+-NOT DETERMINISTIC-+----->
                    |      (2) (3) |  '-DETERMINISTIC-----'   
                    '-JAVA---------'                          

                                                       (3)     
>--+-RETURNS NULL ON NULL INPUT-+--+-MODIFIES SQL DATA-----+---->
   '-CALLED ON NULL INPUT-------'  +-READS SQL DATA--------+   
                                   +-CONTAINS SQL----------+   
                                   '-NO SQL----------------'   

>--+-NO EXTERNAL ACTION-+--+-PACKAGE PATH--package-path-+------->
   '-EXTERNAL ACTION----'  '-NO PACKAGE PATH------------'   

>--+-NO SCRATCHPAD----------+--+-NO FINAL CALL-+---------------->
   '-SCRATCHPAD----length---'  '-FINAL CALL----'   

                    (3)                    
>--+-ALLOW PARALLEL-----+--+-NO DBINFO-+------------------------>
   '-DISALLOW PARALLEL--'  '-DBINFO----'   

                        (4)                              
>--CARDINALITY--integer------+-NO COLLID-------------+---------->
                             '-COLLID--collection-id-'   

>--WLM ENVIRONMENT--+-name-------------+------------------------>
                    '-(--name--,--*--)-'   

>--ASUTIME--+-NO LIMIT-------+--STAY RESIDENT--+-NO--+---------->
            '-LIMIT--integer-'                 '-YES-'   

>--PROGRAM TYPE--+-SUB--+--SECURITY--+-DB2-----+---------------->
                 '-MAIN-'            +-USER----+   
                                     '-DEFINER-'   

>--+-STOP AFTER SYSTEM DEFAULT FAILURES-+----------------------->
   +-STOP AFTER--integer--FAILURES------+   
   '-CONTINUE AFTER FAILURE-------------'   

>--RUN OPTIONS--run-time-options-------------------------------->

>--+-INHERIT SPECIAL REGISTERS-+--STATIC DISPATCH--------------->
   '-DEFAULT SPECIAL REGISTERS-'                    

>--+-SECURED-----+---------------------------------------------><
   '-NOT SECURED-'   

Notes:
  1. If LANGUAGE is JAVA, EXTERNAL NAME must be specified with a valid external-java-routine-name.
  2. When LANGUAGE JAVA is specified, PARAMETER STYLE JAVA must also be specified. When PARAMETER STYLE JAVA is specified, LANGUAGE JAVA must also be specified.
  3. LANGUAGE JAVA, PARAMETER STYLE JAVA, MODIFIES SQL DATA, and ALLOW PARALLEL are not supported for external table functions.
  4. CARDINALITY is not supported for external scalar functions.
Read syntax diagram
external-java-routine-name

|--+-----------+--method-name--+------------------+-------------|
   '-jar-name:-'               '-method-signature-'   

jar-name

|--+--------------+--jar-id-------------------------------------|
   '-schema-name.-'           

method-name

   .--------------------------.                         
   V                          |                         
|----+----------------------+-+--+-.-----+--method-id-----------|
     '-package-id-+-.-----+-'    |   (2) |              
                  |   (1) |      '-!-----'              
                  '-/-----'                             

method-signature

|--+---------------------------+--------------------------------|
   '-(-+-------------------+-)-'   
       | .-,-------------. |       
       | V               | |       
       '---java-datatype-+-'       

Notes:
  1. The slash (/) is supported for compatibility with previous releases of DB2® for z/OS®.
  2. The exclamation point (!) is supported for compatibility with other products in the DB2 family.
End of change

Description

One of the following three clauses identifies the function to be changed.

FUNCTION function-name
Identifies the external function by its function name. function-name must identify a function that exists at the current server. The function must be a user-defined external function, and there must be exactly one function with function-name in the schema.

The function can have any number of input parameters. If the schema does not contain a function with function-name or contains more than one function with this name, an error occurs.

FUNCTION function-name (parameter-type,...)
Identifies the external function by its function signature, which uniquely identifies the function.
function-name
Identifies the function by its name.

If function-name() is specified, the function that is identified must have zero parameters.

(parameter-type,...)
Identifies the number of input parameters of the function and their data types.

The data type of each parameter must match the data type that was specified in the CREATE FUNCTION statement for the parameter in the corresponding position. The number of data types and the logical concatenation of the data types are used to uniquely identify the function. Therefore, you cannot change the number of parameters or the data types of the parameters.

For data types that have a length, precision, or scale attribute, you can use a set of empty parentheses, specify a value, or accept the default values:

If the function was defined with a table parameter (the LIKE TABLE name AS LOCATOR clause was specified in the CREATE FUNCTION statement to indicate that one of the input parameters is a transition table), the function signature cannot be used to uniquely identify the function. Instead, use one of the other syntax variations to identify the function with its function name, if unique, or its specific name.

  • Empty parentheses indicate that DB2 is to ignore the attribute when determining whether the data types match.

    For example, DEC() will be considered a match for a parameter of a function defined with a data type of DEC(7,2). Similarly DECFLOAT() will be considered a match for DECFLOAT(16) or DECFLOAT(34).

    FLOAT cannot be specified with empty parentheses because its parameter value indicates different data types (REAL or DOUBLE).

  • If you use a specific value for a length, precision, or scale attribute, the value must exactly match the value that was specified (implicitly or explicitly) in the CREATE FUNCTION statement.

    The specific value for FLOAT(n) does not have to exactly match the defined value of the source function because 1<=n<=21 indicates REAL and 22<=n<=53 indicates DOUBLE. Matching is based on whether the data type is REAL or DOUBLE.

  • If length, precision, or scale is not explicitly specified and empty parentheses are not specified, the default length of the data type is implied. The implicit length must exactly match the value that was specified (implicitly or explicitly) in the CREATE FUNCTION statement.

For data types with a subtype or encoding scheme attribute, specifying the FOR subtype DATA clause or the CCSID clause is optional. Omission of either clause indicates that DB2 is to ignore the attribute when determining whether the data types match. If you specify either clause, it must match the value that was implicitly or explicitly specified in the CREATE FUNCTION statement.

See CREATE FUNCTION for more information on the specification of the parameter list.

A function with the function signature must exist in the explicitly or implicitly specified schema.

SPECIFIC FUNCTION specific-name
Identifies the external function by its specific name. A function with the specific name must exist in the schema.

The following clauses change the description of the function that has been identified to be changed.

EXTERNAL NAME external-program-name or identifier
Identifies the user-written code (program) that runs when the function is invoked.

If LANGUAGE is JAVA, external-program-name must be specified and enclosed in single quotation marks, with no extraneous blanks within the single quotation marks. It must specify a valid external-java-routine-name. If multiple external-program-name values are specified, the total length of all of them must not be greater than 1305 bytes and they must be separated by a space or a line break. Do not specify a JAR file for a Java function for which NO SQL is in effect.

An external-java-routine-name contains the following parts:
jar-name
Identifies the name given to the JAR file when it was installed in the database. The name contains jar-id, which can optionally be qualified with a schema. Examples are "myJar" and "mySchema.myJar." The unqualified jar-id is implicitly qualified with a schema name according to the following rules:
  • If the statement is embedded in a program, the schema name is the authorization ID in the QUALIFIER option of the BIND subcommand for a package or plan when the package or plan was created or last changed. The schema name can also be the authorization ID in the QUALIFIER option of the CREATE PROCEDURE or ALTER PROCEDURE statement for a native SQL procedure when the procedure was created or last changed. If the QUALIFIER is not specified, the schema name is the owner of the package, plan, or native SQL procedure.
  • If the statement is dynamically prepared, the schema name is the SQL authorization ID in the CURRENT SCHEMA special register.

If jar-name is specified, it must exist when the ALTER FUNCTION statement is processed.

If jar-name is not specified, the function is loaded from the class file directly. DB2 searches the directories in the CLASSPATH associated with the WLM Environment. Environmental variables for Java routines are specified in a data set identified in a JAVAENV DD card on the JCL used to start the address space for a WLM-managed function.

method-name
Identifies the name of the method and must not be longer than 254 bytes. Its package, class, and method IDs are specific to Java and as such are not limited to 18 bytes. In addition, the rules for what method IDs can contain are not necessarily the same as the rules for an SQL ordinary identifier.
package-id
Identifies a package. The concatenated list of package-ids identifies the package that the class identifier is part of. If the class is part of a package, the method name must include the complete package prefix, such as "myPacks.UserFuncs." The Java virtual machine looks in the directory "/myPacks/UserFuncs/" for the classes.
class-id
Identifies the class identifier of the Java object.
method-id
Identifies the method identifier with the Java class to be invoked.
method-signature
Identifies a list of zero or more Java data types for the parameter list and must not be longer than 1024 bytes. Specify the method-signature if the user-defined function involves any input or output parameters that can be NULL. When the function that is being created is called, DB2 searches for a Java method with the exact method-signature. The number of java-datatype elements that are specified indicates how many parameters that the Java method must have.

A Java procedure can have no parameters. In this case, you code an empty set of parentheses for method-signature. If a Java method-signature is not specified, DB2 searches for a Java method with a signature derived from the default JDBC types associated with the SQL types specified in the parameter list of the ALTER FUNCTION statement.

For other values of LANGUAGE, the value must conform to the naming conventions for load modules: the value must be less than or equal to 8 bytes, and it must conform to the rules for an ordinary identifier with the exception that it must not contain an underscore.

LANGUAGE
Specifies the application programming language in which the function is written. All programs must be designed to run in IBM®'s Language Environment® environment.
ASSEMBLE
The function is written in Assembler.
C
The function is written in C or C++.
COBOL
The function is written in COBOL, including the object-oriented language extensions.
JAVA
The user-defined function is written in Java and is executed in the Java virtual machine. If the ALTER FUNCTION statement results in changing LANGUAGE to JAVA, PARAMETER STYLE JAVA and an EXTERNAL NAME clause must be specified to provide the appropriate values. When LANGUAGE JAVA is specified, the EXTERNAL NAME clause must also be specified with a valid external-java-routine-name and PARAMETER STYLE must be specified with JAVA.

Do not specify LANGUAGE JAVA when SCRATCHPAD, FINAL CALL, DBINFO, PROGRAM TYPE MAIN, or RUN OPTIONS is specified. Do not specify LANGUAGE JAVA for a table function.

PLI
The function is written in PL/I.
PARAMETER STYLE
Specifies the linkage convention that the function program uses to receive input parameters from and pass return values to the invoking SQL statement.
SQL
Specifies the parameter passing convention that supports passing null values both as input and for output. The parameters that are passed between the invoking SQL statement and the function include:
  • Input parameters. The first n parameters are the input parameters that are specified for the function.
  • Result parameters. For an external scalar function, a parameter for the result of the function. For an external table function, the next m parameters that are specified on the RETURNS TABLE clause of the CREATE statement that defined the function.
  • Input parameter indicator variables. n parameters for the indicator variables for the input parameters.
  • Result parameter indicator variables. For an external scalar function, a parameter for the indicator variable for the result of the function that is specified on the RETURNS clause of the CREATE statement that defined the function. For an external table function, m parameters for the indicator variables of the result columns of the function that are specified on the RETURNS TABLE clause of the CREATE statement that defined the function.
  • The SQLSTATE to be returned to DB2.
  • The qualified name of the function.
  • The specific name of the function.
  • The SQL diagnostic string to be returned to DB2.
  • The scratchpad, if SCRATCHPAD is specified.
  • The call type. For an external scalar function, the call type is passed only if FINAL CALL is specified. The call type is always passed for an external table function.
  • The DBINFO structure, if DBINFO is specified.
JAVA
Indicates that the user-defined function uses a convention for passing parameters that conforms to the Java and SQLJ specifications. If the ALTER FUNCTION statement results in changing LANGUAGE to JAVA, PARAMETER STYLE JAVA and an EXTERNAL NAME clause must be specified to provide the appropriate values. PARAMETER STYLE JAVA can be specified only if LANGUAGE is JAVA. JAVA must be specified for PARAMETER STYLE when LANGUAGE is JAVA.

Do not specify PARAMETER STYLE JAVA for a table function.

NOT DETERMINISTIC or DETERMINISTIC
Specifies whether the function returns the same results each time that the function is invoked with the same input arguments.
NOT DETERMINISTIC
The function might not return the same result each time that the function is invoked with the same input arguments. The function depends on some state values that affect the results. DB2 uses this information to disable the merging of views and table expressions when processing SELECT or SQL data change statements that refer to this function. An example of a function that is not deterministic is one that generates random numbers, or any function that contains SQL statements.

Some SQL functions that invoke functions that are not deterministic can receive incorrect results if the function is executed by parallel tasks. Specify the DISALLOW PARALLEL clause for these functions.

If a view or a materialized query table definition refers to the function, the function cannot be changed to NOT DETERMINISTIC. To change the function, drop any views or materialized query tables that refer to the function first.

DETERMINISTIC
The function always returns the same result each time that the function is invoked with the same input arguments. An example of a deterministic function is a function that calculates the square root of the input. DB2 uses this information to enable the merging of views and table expressions for SELECT or SQL data change statements that refer to this function. If applicable, specify DETERMINISTIC to prevent non-optimal access paths from being chosen for SQL statements that refer to this function.

DB2 does not verify that the function program is consistent with the specification of DETERMINISTIC or NOT DETERMINISTIC.

RETURNS NULL ON NULL INPUT or CALLED ON NULL INPUT
Specifies whether the function is called if any of the input arguments is null at execution time.
RETURNS NULL ON NULL INPUT
The function is not called if any of the input arguments is null. For an external scalar function, the result is the null value. For an external table function, the result is an empty table, which is a table with no rows.
CALLED ON NULL INPUT
The function is called regardless of whether any of the input arguments are null, making the function responsible for testing for null argument values. For an external scalar function, the function can return a null or nonnull value. For an external table function, the function can return an empty table, depending on its logic.
MODIFIES SQL DATA, READS SQL DATA, CONTAINS SQL, or NO SQL
Specifies the classification of SQL statements and nested routines that this routine can execute or invoke. The database manager verifies that the SQL statements issued by the function, and all routines locally invoked by the routine, are consistent with this specification; the verification is not performed when nested remote routines are invoked. For the classification of each statement, see SQL statement data access classification for routines.
MODIFIES SQL DATA
Specifies that the function can execute any SQL statement except the statements that are not supported in functions. Do not specify MODIFIES SQL DATA when ALLOW PARALLEL is in effect.
READS SQL DATA
Specifies that the function can execute statements with a data access indication of READS SQL DATA, CONTAINS SQL, or NO SQL. The function cannot execute SQL statements that modify data.
CONTAINS SQL
Specifies that the function can execute only SQL statements with a data classification of CONTAINS SQL or NO SQL. SQL statements that neither read nor modify SQL data can be executed by the function. Statements that are not supported in any function return a different error.
NO SQL
Specifies that the function can execute only SQL statements with a data access classification of NO SQL. Do not specify NO SQL for a Java function that uses a JAR file.
NO EXTERNAL ACTION or EXTERNAL ACTION
Specifies whether the function takes an action that changes the state of an object that DB2 does not manage. An example of an external action is sending a message or writing a record to a file.

Because DB2 uses the RRS attachment for external functions, DB2 can participate in two-phase commit with any other resource manager that uses RRS. For resource managers that do not use RRS, there is no coordination of commit or rollback operations on non-DB2 resources.

NO EXTERNAL ACTION
The function does not take any action that changes the state of an object that DB2 does not manage. DB2 uses this information to enable the merging of views and table expressions for SELECT or SQL data change statements that refer to this function. If applicable, specify NO EXTERNAL ACTION to prevent non-optimal access paths from being chosen for SQL statements that refer to this function.
EXTERNAL ACTION
The function can take an action that changes the state of an object that DB2 does not manage.

Some SQL statements that invoke functions with external actions can result in incorrect results if parallel tasks execute the function. For example, if the function sends a note for each initial call to it, one note is sent for each parallel task instead of once for the function. Specify the DISALLOW PARALLEL clause for functions that do not work correctly with parallelism.

If you specify EXTERNAL ACTION, DB2:

  • Materializes the views and table expressions in SELECT or SQL data change statements that refer to the function. This materialization can adversely affect the access paths that are chosen for the SQL statements that refer to this function. Do not specify EXTERNAL ACTION if the function does not have an external action.
  • Does not move the function from one task control block (TCB) to another between FETCH operations.
  • Does not allow another function or stored procedure to use the TCB until the cursor is closed. This is also applicable for cursors declared WITH HOLD.

The only changes to resources made outside of DB2 that are under the control of commit and rollback operations are those changes made under RRS control.

If a view or a materialized query table definition refers to the function, the function cannot be changed to EXTERNAL ACTION. To change the function, drop any views or materialized query tables that refer to the function first.

DB2 does not verify that the function program is consistent with the specification of EXTERNAL ACTION or NO EXTERNAL ACTION.

NO PACKAGE PATH or PACKAGE PATH package-path
Identifies the package path to use when the function is run. This is the list of the possible package collections into which the DBRM that is associated with the function is bound.
NO PACKAGE PATH
Specifies that the list of package collections for the function is the same as the list of package collections for the program that invokes the function. If the program that invokes the function does not use a package, DB2 resolves the package by using the CURRENT PACKAGE PATH special register, the CURRENT PACKAGESET special register, or the PKLIST bind option (in this order). For information about how DB2 uses these three items, see DB2 Application Programming and SQL Guide.
PACKAGE PATH package-path
Specifies a list of package collections, in the same format as used in the SET CURRENT PACKAGE PATH statement.

If the COLLID clause is specified with PACKAGE PATH, the COLLID clause is ignored when the function is invoked.

The package-path value that is associated with the function definition is checked when the function is invoked. If package-path contains SESSION_USER (or USER), PATH, or PACKAGE PATH, an error is returned when the package-path value is checked.

NO SCRATCHPAD or SCRATCHPAD
Specifies whether DB2 is to provide a scratchpad for the function. Using reentrant external functions and a scratchpad (which provides an area for the function to save information from one invocation to the next) is strongly recommended.
NO SCRATCHPAD
A scratchpad is not allocated and passed to the function.
SCRATCHPAD length
When the function is invoked for the first time, DB2 allocates memory for a scratchpad. A scratchpad has the following characteristics:
  • length must be between 1 and 32767. The default value is 100 bytes.
  • DB2 initializes the scratchpad to all binary zeros (X'00').
  • The scope of a scratchpad is the SQL statement. For each reference to the function in an SQL statement, there is one scratchpad.
    For example, assuming that user-defined function UDFX is a scalar function that is defined with the SCRATCHPAD option, three scratchpads are allocated for the three references to UDFX in the following SQL statement:
       SELECT A, UDFX(A) FROM TABLEB
         WHERE UDFX(A) > 103 OR UDFX(A) < 19;
    For another example, assume that UDFX is a user-defined table function that is defined with the SCRATCHPAD option. Two scratchpads are allocated for the two references to function UDFX in the following SQL statement:
       SELECT *
         FROM TABLE (UDFX(A)), TABLE (UDFX(B)); 

    If the function is run under parallel tasks, one scratchpad is allocated for each parallel task of each reference to the function in the SQL statement. This can lead to unpredictable results. For example, if a function uses the scratchpad to count the number of times that it is invoked, the count reflects the number of invocations done by the parallel task and not the SQL statement. Specify the DISALLOW PARALLEL clause for functions that do not work correctly with parallelism.

  • The scratchpad is persistent. DB2 preserves its content from one invocation of the function to the next. Any changes that the function makes to the scratchpad on one call are still there on the next call. DB2 initializes the scratchpads when it begins to execute an SQL statement. DB2 does not reset scratchpads when a correlated subquery begins to execute.
  • The scratchpad can be a central point for the system resources that the function acquires. If the function acquires system resources, specify FINAL CALL to ensure that DB2 calls the function one more time so that the function can free those system resources.

Each time that the function is invoked, DB2 passes an additional argument to the function that contains the address of the scratchpad.

If you specify SCRATCHPAD, DB2:

  • Does not move the function from one TCB or address space to another between FETCH operations.
  • Does not allow another function or stored procedure to use the TCB until the cursor is closed. This is also applicable for cursors declared WITH HOLD.

Do not specify SCRATCHPAD when LANGUAGE JAVA is specified.

NO FINAL CALL or FINAL CALL
Specifies whether a final call is made to the function. A final call enables the function to free any system resources that it has acquired. A final call is useful when the function has been defined with the SCRATCHPAD keyword and the function acquires system resource and anchors them in the scratchpad.

The effect of NO FINAL CALL or FINAL CALL depends on whether the external function is a scalar function or a table function.

For an external scalar function:
NO FINAL CALL
A final call is not made to the external scalar function. The function does not receive an additional argument that specifies the type of call.
FINAL CALL
A final call is made to the external scalar function. See the following description of call types for the characteristics of a final call. When FINAL CALL is specified, the function receives an additional argument that specifies the type of call to enable the function to differentiate between a final call and another type of call. Do not specify FINAL CALL when LANGUAGE JAVA is specified.
For more information on NO FINAL CALL and FINAL CALL for external scalar functions, including the types of calls, see the description of the option for CREATE FUNCTION (external scalar).
For an external table function:
NO FINAL CALL
A first and final call are not made to the external table function.
FINAL CALL
A first call and final call are made to the external table function in addition to one or more other types of calls.
For both NO FINAL CALL and FINAL CALL, the function receives an additional argument that specifies the type of call. For more information on NO FINAL CALL and FINAL CALL for external table functions, including the types of calls, see the description of the option for CREATE FUNCTION (external table).
ALLOW or DISALLOW PARALLEL
Specifies whether, for a single reference to the function, the function can be executed in parallel. If the function is defined with MODIFIES SQL DATA, specify DISALLOW PARALLEL, not ALLOW PARALLEL.
ALLOW PARALLEL
Specifies that DB2 can consider parallelism for the function. Parallelism is not forced on the SQL statement that invokes the function or on any SQL statement in the function. Existing restrictions on parallelism apply.

See SCRATCHPAD, EXTERNAL ACTION, and FINAL CALL for considerations when specifying ALLOW PARALLEL.

DISALLOW PARALLEL
Specifies that DB2 does not consider parallelism for the function.
NO DBINFO or DBINFO
Specifies whether additional status information is passed to the function when it is invoked.
NO DBINFO
Additional information is not passed.
DBINFO
An additional argument is passed when the function is invoked. The argument is a structure that contains information such as the application run time authorization ID, the schema name, the name of a table or column that the function might be inserting into or updating, and identification of the database server that invoked the function. For details about the argument and its structure, see DB2 Application Programming and SQL Guide.

Do not specify DBINFO when LANGUAGE JAVA is specified.

CARDINALITY integer
Specifies an estimate of the expected number of rows that the function returns. The number is used for optimization purposes. The value of integer must range from 0 to 2147483647.

If a function has an infinite cardinality (which means that the function never returns the "end-of-table" condition and always returns a row), a query that requires the end-of-table condition to work correctly needs to be interrupted. Thus, avoid using such functions in queries that involve GROUP BY and ORDER BY.

Do not specify CARDINALITY for external scalar functions.

NO COLLID or COLLID collection-id
Identifies the package collection that is to be used when the function is executed. This is the package collection into which the DBRM that is associated with the function is bound.
NO COLLID
Specifies the package collection for the function is the same as the package collection of the program that invokes the function. If a trigger invokes the function, the collection of the trigger package is used. If the invoking program does not use a package, DB2 resolves the package by using the CURRENT PACKAGE PATH special register, the CURRENT PACKAGESET special register, or the PKLIST bind option (in this order). For details about how DB2 uses these three items, see the information on package resolution in DB2 Application Programming and SQL Guide.
COLLID collection-id
Specifies the name of the package collection that is to be used when the function is executed.
WLM ENVIRONMENT
An SQL identifier that identifies the name of the WLM (workload manager) application environment in which the function is to run.
name
The WLM environment in which the function must run. If the user-defined function is nested and if the calling stored procedure or invoking user-defined function is not running in an address space associated with the specified WLM environment, DB2 routes the function request to a different address space.
(name,*)
When an SQL application program calls the function, name specifies the WLM environment in which the function runs.

If another user-defined function or a stored procedure calls the function, the function runs in the same environment that the calling routine uses. In this case, authorization to run the function in the WLM environment is not checked because the authorization of the calling routine suffices.

The name of the WLM environment is an SQL identifier.

To change the environment in which the function is to run, you must have appropriate authority for the WLM environment. For an example of a RACF command that provides this authorization, see Running stored procedures.

ASUTIME
Specifies the total amount of processor time, in CPU service units, that a single invocation of the function can run. The value is unrelated to the ASUTIME column of the resource limit specification table.

When you are debugging a function, setting a limit can be helpful if the function gets caught in a loop. For information on service units, see z/OS MVS Initialization and Tuning Guide.

NO LIMIT
There is no limit on the service units.
LIMIT integer
Start of changeThe limit on the number of CPU service units is a positive integer in the range of 1 to 2 147 483 647. If the procedure uses more service units than the specified value, DB2 cancels the procedure. The CPU cycles that are consumed by parallel tasks in a procedure do not contribute towards the specified ASUTIME LIMIT.End of change
STAY RESIDENT
Specifies whether the load module for the function is to remain resident in memory when the function ends.
NO
The load module is deleted from memory after the function ends. Use NO for non-reentrant functions.
YES
The load module remains resident in memory after the function ends. Use YES for reentrant functions.
PROGRAM TYPE
Specifies whether the function program runs as a main routine or a subroutine.
SUB
The function runs as a subroutine.
MAIN
The function runs as a main routine.

Do not specify PROGRAM TYPE MAIN when LANGUAGE JAVA is in effect.

SECURITY
Specifies how the function interacts with an external security product, such as RACF, to control access to non-SQL resources.
DB2
The function does not require an external security environment. If the function accesses resources that an external security product protects, the access is performed using the authorization ID associated with the WLM-established stored procedure address space.
USER
An external security environment should be used with the function. If the function accesses resources that the external security product protects, the access is performed using the primary authorization ID of the process that invoked the function.
DEFINER
An external security environment should be used with the function. If the function accesses resources that the external security product protects, the access is performed using the authorization ID of the owner of the function.
STOP AFTER SYSTEM DEFAULT FAILURES, STOP AFTER nn FAILURES, or CONTINUE AFTER FAILURE
Specifies whether the routine is to be put in a stopped state after some number of failures. The following options must not be specified for SQL functions or sourced functions.
STOP AFTER SYSTEM DEFAULT FAILURES
Specifies that this routine should be placed in a stopped state after the number of failures indicated by the value of field MAX ABEND COUNT on installation panel DSNTIPX.
STOP AFTER nn FAILURES
Specifies that this routine should be placed in a stopped state after nn failures. The value nn can be an integer from 1 to 32767.
CONTINUE AFTER FAILURE
Specifies that this routine should not be placed in a stopped state after any failure.
RUN OPTIONS run-time-options
Specifies the Language Environment run time options to be used for the function. You must specify run-time-options as a character string that is no longer than 254 bytes. To replace any existing run time options with no options, specify an empty string with RUN OPTIONS. When you specify an empty string, DB2 does not pass any run time options to Language Environment, and Language Environment uses its installation defaults.

For a description of the Language Environment run time options, see z/OS Language Environment Programming Reference.

Do not specify RUN OPTIONS when LANGUAGE JAVA is specified.

INHERIT SPECIAL REGISTERS or DEFAULT SPECIAL REGISTERS
Specifies how special registers are set on entry to the routine.
INHERIT SPECIAL REGISTERS
Specifies that special registers should be inherited according to the rules listed in the table for characteristics of special registers in a user-defined function in Special registers in a user-defined function or a stored procedure.
DEFAULT SPECIAL REGISTERS
Specifies that special registers should be initialized to the default values, as indicated by the rules in the table for characteristics of special registers in a user-defined function in Special registers in a user-defined function or a stored procedure.
STATIC DISPATCH
At function resolution time, DB2 chooses a function based on the static (or declared) types of the function parameters.
Start of changeSECURED or NOT SECUREDEnd of change
Start of changeSpecifies whether the function is considered secure.
SECURED
Specifies that the function is considered secure.
NOT SECURED
Specifies that the function is considered not secure. NOT SECURED must not be specified when a row permission or a column mask depends on the function.

When the function is invoked, the arguments of the function must not reference a column for which a column mask is enabled when the table is using active column access control.

End of change

Notes

Invalidation of packages:
This statement might invalidate all packages that depend on target objects, and sometimes other related objects through cascading effects, depending on the clauses and keywords specified and other factors. See Changes that invalidate packages.
LANGUAGE C and the PARAMETER VARCHAR clause:
The ALTER statement does not allow you to alter the value of the PARAMETER VARCHAR or PARAMETER CCSID clauses that are associated with the function definition. However, you can alter the LANGUAGE clause for the function. If the PARAMETER VARCHAR clause is specified for the creation of a LANGUAGE C function, the catalog information for that option is not affected by a subsequent ALTER function statement. The function might be changed to a language other than C, in which case the PARAMETER VARCHAR setting is ignored. If the function is later changed back to LANGUAGE C, the setting of the PARAMETER VARCHAR option that was specified during the CREATE FUNCTION statement will be used.
Start of changeAltering a function from NOT SECURED to SECURED:End of change
Start of changeTypically, the security administrator will examine the data that is accessed by a function, ensure that it is secure, and grant the CREATE_SECURE_OBJECT privilege to the user that requires privileges to change the user-defined function to be secured. After the function is changed to SECURED, the security administrator will revoke the CREATE_SECURE_OBJECT privilege from the owner of the function.

The function is considered secure after the ALTER FUNCTION statement is executed. DB2 treats the SECURED attribute as an assertion that declares that the security administrator has established an audit procedure for all changes to the user-defined function. DB2 assumes that such a control audit procedure is in place for all subsequent ALTER FUNCTION statements or changes to external packages.

Packages and statements in the dynamic statement cache that reference the function are invalidated.

End of change
Start of changeAltering a function from SECURED to NOT SECURED:End of change
Start of changePackages and statements in the dynamic statement cache that reference the function are invalidated when the function is changed from SECURED to NOT SECURED. An function that is not secured might negatively impact performance if that function accesses data in a table that is using row access control or column access control. To minimize the performance impact, either change the function to use the SECURED option or deactivate row access control or column access control for the table that the function is accessing.End of change
Start of changeInvoking other user-defined functions in a secure function:End of change
Start of changeWhen a secure user-defined function is referenced in an SQL data change statement that references a table that is using row access control or column access control, and if the secure user-defined function invokes other user-defined functions, the nested user-defined functions are not validated as secure. If those nested functions can access sensitive data, the security administrator needs to ensure that those functions are allowed to access sensitive data and should ensure that a change control audit procedure has been established for all changes to those functions.End of change
Start of changeThe SECURE column in the DSN_FUNCTION_TABLE EXPLAIN table:End of change
Start of changeThe SECURE column in the DSN_FUNCTION_TABLE EXPLAIN table indicates if a user-defined function is considered secure.End of change
Alternative syntax and synonyms:
To provide compatibility with previous releases of DB2 or other products in the DB2 family, DB2 supports the following keywords:
  • VARIANT as a synonym for NOT DETERMINISTIC
  • NOT VARIANT as a synonym for DETERMINISTIC
  • NOT NULL CALL as a synonym for RETURNS NULL ON NULL INPUT
  • NULL CALL as a synonym for CALLED ON NULL INPUT
  • PARAMETER STYLE DB2SQL as a synonym for PARAMETER STYLE SQL
  • Start of changeTIMEZONE can be specified as an alternative to TIME ZONE.End of change

Examples

Example 1: Assume that two functions CENTER are in the PELLOW schema. The first function has two input parameters with INTEGER and FLOAT data types, respectively. The specific name for the first function is FOCUS1. The second function has three parameters with CHAR(25), DEC(5,2), and INTEGER data types.

Using the specific name to identify the function, change the WLM environment in which the first function runs from WLMENVNAME1 to WLMENVNAME2:
   ALTER SPECIFIC FUNCTION ENGLES.FOCUS1 WLM ENVIRONMENT WLMENVNAME2;
Example 2: Change the second function that is described in Example 1 so that it is not invoked when any of the arguments are null. Use the function signature to identify the function:
   ALTER FUNCTION ENGLES.CENTER (CHAR(25), DEC(5,2), INTEGER)
      RETURNS NULL ON NULL INPUT;
You can also code the ALTER FUNCTION statement without the exact values for the CHAR and DEC data types:
   ALTER FUNCTION ENGLES.CENTER (CHAR(), DEC(), INTEGER)
      RETURNS NULL ON NULL INPUT;

If you use empty parentheses, DB2 is to ignore the length, precision, and scale attributes when looking for matching data types to find the function.