Example: Table UDF with Fixed Result Row Specification - Analytics Database - Teradata Vantage

SQL External Routine Programming

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2023-07-11
dita:mapPath
iiv1628111441820.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
B035-1147
lifecycle
latest
Product Category
Teradata Vantage™

Here is a code excerpt that shows the method signature for a method that implements a table UDF:

public class UDFExample {

   ...

   public static void getStoreData( int   storedata,  /* input arg */
                                    int[] storeno,    /* output arg */
                                    int[] itemno,     /* output arg */
                                    int[] quantsold)  /* output arg */
   {
        ...
   }

   ...

}

If the JAR file for the UDFExample class is called UDFExample.jar, the following statement registers UDFExample.jar and the UDFExample class with the database, and creates an SQL identifier called JarUDF for the JAR file:

CALL SQLJ.INSTALL_JAR('CJ!udfsrc/UDFExample.jar','JarUDF',0);

The corresponding CREATE FUNCTION statement to define the UDF looks like this :

CREATE FUNCTION getStoreData
  (FileToRead INTEGER)
RETURNS TABLE
   (StoreNo   INTEGER
   ,ItemNo    INTEGER
   ,QuantSold INTEGER)
LANGUAGE JAVA
NO SQL
EXTERNAL NAME 'JarUDF:UDFExample.getStoreData'
PARAMETER STYLE JAVA;

Here is an example of an INSERT ... SELECT statement that invokes the table function in the FROM clause:

INSERT INTO Sales_Table
SELECT *
FROM TABLE (getStoreData(9005)) AS tf;