17.10 - Examples - Advanced SQL Engine - Teradata Database

Teradata Vantageā„¢ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1147-171K
Language
English (United States)

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