Creates an interface to an external table user-defined function (table UDF). Users must be specifically licensed to use table UDFs.
Quick Links:
CREATE[ OR REPLACE ] PROCEDURE [ owner.]procedure-name ( [ parameter[, …]] ) | RESULT result-column [, …] ) [ SQL SECURITY { INVOKER | DEFINER } ] EXTERNAL NAME ‘external-call’ parameter - (back to Syntax) [ IN ] parameter-name data-type [ DEFAULT expression ] | [ IN ] parameter-name table-type table-type - (back to parameter) TABLE( column-name data-type [, ...] ) external-call - (back to Syntax) [column-name:]function-name@library; ...
A TPF cannot produce LOB data, but can have columns in the result set as LOB data types. However, the only way to get LOB data in the output is to pass a column from an input table to the output table. The describe attribute EXTFNAPIV4_DESCRIBE_COL_VALUES_SUBSET_OF_INPUT allows this, as illustrated in the sample file tpf_blob.cxx.
When SQL SECURITY INVOKER is specified, more memory is used because annotation must be done for each user that calls the procedure. Also, when SQL SECURITY INVOKER is specified, name resolution is done as the invoker as well. Therefore, care should be taken to qualify all object names (tables, procedures, and so on) with their appropriate owner. For example, suppose user1 creates this procedure:
CREATE PROCEDURE user1.myProcedure() RESULT( columnA INT ) SQL SECURITY INVOKER BEGIN SELECT columnA FROM table1; END;
If user2 attempts to run this procedure and a table user2.table1 does not exist, a table lookup error results. Additionally, if a user2.table1 does exist, that table is used instead of the intended user1.table1. To prevent this situation, qualify the table reference in the statement (user1.table1, instead of just table1).
The library name can include the file extension, which is typically .dll on Windows and .so on UNIX. In the absence of the extension, the software appends the platform-specific default file extension for libraries. This is a formal example.
CREATE PROCEDURE mystring( IN instr CHAR(255), IN input_table TABLE(A INT) ) RESULT (CHAR(255)) EXTERNAL NAME 'mystring@mylib.dll;Unix:mystring@mylib.so'
CREATE PROCEDURE mystring( IN instr CHAR(255), IN input_table TABLE(A INT) ) RESULT (CHAR(255)) EXTERNAL NAME ‘mystring@mylib’
You define table UDFs using the a_v4_extfn API. CREATE PROCEDURE statement reference information for external procedures that do not use the a_v3_extfn or a_v4_extfn APIs is located in a separate topic. CREATE PROCEDURE statement reference information for Java UDFs is located in a separate topic.
The CREATE PROCEDURE statement creates a procedure in the database. To create a procedure for themselves, a user must have the CREATE PROCEDURE system privilege. To create a procedure for others, a user must specify the owner of the procedure and must have either the CREATE ANY PROCEDURE or CREATE ANY OBJECT system privilege. If the procedure contains an external reference, the user must have the CREATE EXTERNAL REFERENCE system privilege in addition to previously mentioned system privileges, regardless of who owns the procedure.
If a stored procedure returns a result set, it cannot also set output parameters or return a return value.
When referencing a temporary table from multiple procedures, a potential issue can arise if the temporary table definitions are inconsistent and statements referencing the table are cached. Use caution when referencing temporary tables within procedures.
You can use the CREATE PROCEDURE statement to create external table UDFs implemented in a different programming language than SQL. However, be aware of the table UDF restrictions before creating external UDFs.
The data type for a scalar parameter, a result column, and a column of a TABLE parameter must be a valid SQL data type.
Parameter names must conform to the rules for other database identifiers such as column names. They must be a valid SQL data type.
TPFs support a mix scalar parameters and single TABLE parameter. A TABLE parameter must define a schema for an input set of rows to be processed by the UDF. The definition of a TABLE parameter includes column names and column data types.
TABLE(c1 INT, c2 CHAR(20))
The above example defines a schema with the two columns c1 and c2 of types INT and CHAR(20). Each row processed by the UDF must be a tuple with two (2) values. TABLE parameters, unlike scalar parameters cannot be assigned a default value.
Unless creating a temporary procedure, a user must have the CREATE PROCEDURE system privilege to create a UDF for themselves. To create a UDF for others, they must specify the owner of the procedure and must have either the CREATE ANY PROCEDURE or CREATE ANY OBJECT system privilege. If the procedure contains an external reference, a user must also have the CREATE EXTERNAL REFERENCE system privilege, in addition to the previously mentioned system privileges.