Examples - 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™

Example: Using Default Mapping of Parameter Types

Here is a code excerpt that shows how to implement a Java method for an external stored procedure that maps an SQL INTEGER type parameter to the Java int primitive:

public class region {

   public static void newRegion( int[] regionID )
   {
       regionID[0] += 1;
   }

   ...

}

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

CALL SQLJ.INSTALL_JAR('CJ!C:\xspsrc\region.jar','JarXSP',0);

The corresponding CREATE PROCEDURE statement to define the external stored procedure looks like this :

CREATE PROCEDURE NewRegionXSP
  (INOUT regionID INTEGER)
LANGUAGE JAVA
NO SQL
PARAMETER STYLE JAVA
EXTERNAL NAME 'JarXSP:region.newRegion';

Example: Overriding the Default Mapping of Parameter Types

Here is a code excerpt that shows how to implement a Java method for an external stored procedure that maps an SQL INTEGER type parameter to the java.lang.Integer class:

public class region {

   public static void newRegion( Integer[] regionID )
   {
       if (regionID[0] != null)
          regionID[0] = regionID[0].intValue() + 1;
   }

   ...

}

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

CALL SQLJ.INSTALL_JAR('CJ!C:\xspsrc\region.jar','JarXSP',0);

The corresponding CREATE PROCEDURE statement to define the external stored procedure looks like this :

CREATE PROCEDURE NewRegionXSP
  (INOUT regionID INTEGER)
LANGUAGE JAVA
NO SQL
PARAMETER STYLE JAVA
EXTERNAL NAME 'JarXSP:region.newRegion(java.lang.Integer[])';