16.20 - Example: Overloaded Function - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
16.20
Release Date
April 2020
Content Type
Programming Reference
Publication ID
B035-1147-162K
Language
English (United States)

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)';