Creates a new external Java table UDF function in the database.
CREATE [ OR REPLACE | TEMPORARY ] FUNCTION [ owner.]function-name ( [ parameter, … ] ) [ SQL SECURITY { INVOKER | DEFINER } ] RETURNS data-type ON EXCEPTION RESUME | [ NOT ] DETERMINISTIC { compound-statement | AS tsql-compound-statement | EXTERNAL NAME 'java-call' LANGUAGE JAVA [ ALLOW | DISALLOW SERVER SIDE REQUESTS ] environment-name} parameter: IN parameter-name data-type [ DEFAULT expression ] tsql-compound-statement: sql-statement sql-statement … java-call: '[ package-name.]class-name.method-name method-signature' method-signature: ( [ field-descriptor, ….] ) return-descriptor field-descriptor and return-descriptor: Z | B | S | I | J | F | D | C | V | [ descriptor | L class-name;
The CREATE clause creates a new function, while the OR REPLACE clause replaces an existing function with the same name. When a function is replaced, the definition of the function is changed but the existing permissions are preserved. You cannot use the OR REPLACE clause with temporary functions.
Temporary functions execute with the permissions of their creator (current user), and can only be owned by their creator. Therefore, do not specify owner when creating a temporary function. They can be created and dropped when connected to a read-only database.
When INVOKER is specified, more memory is used because annotation must be done for each user that calls the procedure. Also, name resolution is done as the invoker as well. Therefore, take care to qualify all object names (tables, procedures, and so on) with their appropriate owner.
CREATE FUNCTION keygen( increment INTEGER ) RETURNS INTEGER NOT DETERMINISTIC BEGIN DECLARE keyval INTEGER; UPDATE counter SET x = x + increment; SELECT counter.x INTO keyval FROM counter; RETURN keyval END INSERT INTO new_table SELECT keygen(1), ... FROM old_table
CREATE FUNCTION keygen( increment INTEGER ) RETURNS INTEGER NOT DETERMINISTIC BEGIN DECLARE keyval INTEGER; UPDATE counter SET x = x + increment; SELECT counter.x INTO keyval FROM counter; RETURN keyval END INSERT INTO new_table SELECT keygen(1), ... FROM old_table
Functions may be declared as DETERMINISTIC if they always return the same value for given input parameters. All user-defined functions are treated as deterministic unless they are declared NOT DETERMINISTIC. Deterministic functions return a consistent result for the same parameters and are free of side effects. That is, the database server assumes that two successive calls to the same function with the same parameters will return the same result without unwanted side-effects on the semantics of the query.
The DISALLOW clause is the default. The ALLOW clause indicates that server-side connections are allowed.
CREATE FUNCTION dba.encrypt( IN name char(254) ) RETURNS VARCHAR EXTERNAL NAME 'Scramble.encrypt (Ljava/lang/String;)Ljava/lang/String;' LANGUAGE JAVA
When functions are executed, not all parameters need to be specified. If a default value is provided in the CREATE FUNCTION statement, missing parameters are assigned the default values. If an argument is not provided by the caller and no default is set, an error is given.
SQL—ISO/ANSI SQL compliant.
Sybase—Not supported by Adaptive Server Enterprise.
For function to be owned by self – Requires the CREATE PROCEDURE system privilege