17.10 - Usage Notes - 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)

Default Mapping Convention of Parameter Types

The data types that you use in the parameter list of the Java method map to the SQL data types in the parameter list of the CREATE PROCEDURE or REPLACE PROCEDURE statement.

Consider the following CREATE PROCEDURE statement:

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

The parameter list specifies that the SQL data type of regionID is INTEGER. The signature of the newRegion method that implements the external stored procedure looks like this:

public static void newRegion( int regionID ) { ... }

The default mapping convention is simple mapping, where SQL data types map to Java primitives. If no Java primitive can adequately map to an SQL type, then the default mapping convention is object mapping, where SQL data types map to Java classes.

Consider a NewRegionXSP external stored procedure that takes a CHARACTER(30) value:

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

Because the CHARACTER type does not map adequately to a Java primitive, the CHARACTER type maps to java.lang.String. The signature of the newRegion method that implements the external stored procedure looks like this:

public static void newRegion( String regionID ) { ... }

For details on how SQL data types map to Java data types, see SQL Data Type Mapping.

Overriding the Default Mapping of Parameters

For external stored procedures that allow parameters to pass in or return nulls, simple mapping to Java primitives is not appropriate because they cannot represent NULLs.

To override the default mapping, the EXTERNAL NAME clause in the CREATE PROCEDURE or REPLACE PROCEDURE statement must explicitly specify the mapping in the parameter list of the Java method.

CLOB and BLOB Type Mapping

CLOB and BLOB SQL types in the parameter list of the CREATE PROCEDURE or REPLACE PROCEDURE statement map to java.sql.Clob and java.sql.Blob classes respectively.

The data access clause in the CREATE PROCEDURE or REPLACE PROCEDURE statement determines which implementing classes of java.sql.Clob and java.sql.Blob are used. (The data access clause indicates whether the external stored procedure executes SQL statements and, if so, whether the statements read or modify SQL data in the database.)

IF the SQL type is … AND the data access clause is … THEN the Java implementing class is …
BLOB NO SQL com.teradata.fnc.Blob.

For details, see com.teradata.fnc.Blob.

CONTAINS SQL com.teradata.jdbc.jdbc_4.Blob.

For details, see Teradata JDBC Driver Reference, available at https://teradata-docs.s3.amazonaws.com/doc/connectivity/jdbc/reference/current/frameset.html.

READS SQL DATA
MODIFIES SQL DATA
CLOB NO SQL com.teradata.fnc.Clob.

For details, see com.teradata.fnc.Clob.

CONTAINS SQL com.teradata.jdbc.jdbc_4.Clob.

For details, see Teradata JDBC Driver Reference, available at https://teradata-docs.s3.amazonaws.com/doc/connectivity/jdbc/reference/current/frameset.html.

READS SQL DATA
MODIFIES SQL DATA

For details on the data access clause, see Executing SQL in Java External Stored Procedures.