Example: Overloaded Function - Advanced SQL Engine - Teradata Database

SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-27
dita:mapPath
rin1593638965306.ditamap
dita:ditavalPath
rin1593638965306.ditaval
dita:id
B035-1147
lifecycle
previous
Product Category
Teradata Vantage™

Consider the following overloaded Java methods called get_random in the UDFExample class:

public class UDFExample {

   ...

   public static int get_random( int some_value ) {
     ...
   }
   
   public static int get_random( java.sql.Date some_value ) {
     ...
   }

   ...
   
}

The method names are the same, but the data type of the some_value parameter is distinct.

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!C:\udfsrc\UDFExample.jar','JarUDF',0);

Now consider the following function definitions that overload the scalar UDF name UDF_RAN:

CREATE FUNCTION UDF_RAN(SomeValue INTEGER)
RETURNS INTEGER
LANGUAGE JAVA
NO SQL
PARAMETER STYLE JAVA
EXTERNAL NAME 'JarUDF:UDFExample.get_random(int)';

CREATE FUNCTION UDF_RAN(SomeValue DATE)
RETURNS INTEGER
LANGUAGE JAVA
NO SQL
PARAMETER STYLE JAVA
EXTERNAL NAME 'JarUDF:UDFExample.get_random(java.sql.Date)';