16.20 - Argument Behavior - 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)

Truncation of Character String Arguments

The session transaction mode affects character string truncation.

IF the session transaction mode is … THEN an input character string that requires truncation is truncated …
Teradata without reporting an error. Truncation on Kanji1 character strings containing multibyte characters might result in truncation of one byte of the multibyte character.
ANSI of excess pad characters without reporting an error. Truncation of other characters results in a truncation exception.

The normal truncation rules apply to a result string. For more information, see “Character Truncation Rules” in Teradata Vantage™ - Data Types and Literals, B035-1143.

Behavior When Using NULL as a Literal Argument

To properly handle the NULL literal as an input argument, an external stored procedure cannot use the default mapping convention if the SQL data types in the parameter list of the CREATE PROCEDURE or REPLACE PROCEDURE statement map to Java primitives.

To override the default mapping and map SQL data types to Java classes that can handle the NULL literal as an input argument, 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.

For details on how SQL data types map to Java data types, see SQL Data Type Mapping. For an example that shows how to override the default mapping, see "Example: Overriding the Default Mapping of Parameter Types" in Parameter List.

Overflow and Numeric Arguments

To avoid numeric overflow conditions, the Java external stored procedure should define a DECIMAL or NUMERIC data type as big as it can handle.

If the assignment of the value of an input or output numeric argument would result in a loss of significant digits, a numeric overflow error is reported.

For example, consider an external stored procedure that takes a DECIMAL(2,0) argument:

CREATE PROCEDURE smldec( IN p1 DECIMAL(2,0) )
LANGUAGE JAVA
READS SQL DATA
PARAMETER STYLE JAVA
EXTERNAL NAME 'NumJAR:NumClass.smldec';

Passing a number with a maximum of two digits is successful:

CALL smldec(99);

An attempt to pass a number larger than 99 or smaller than -99 would result in a loss of significant digits.

CALL smdec(100);
   
 Failure 2616 Numeric overflow occurred during computation.

Any fractional numeric data that is passed or returned that does not fit as it is being assigned is rounded according to the Teradata rounding rules. For more information on rounding, see “Decimal/Numeric Data Types" in Teradata Vantage™ - Data Types and Literals, B035-1143.

Data Type for INOUT Constant Arguments

The data type for an INOUT constant argument is governed by the data type of the value passed in, not what is defined. If the data type of the value passed in is smaller than the data type defined in the CREATE PROCEDURE or REPLACE PROCEDURE statement, and the external stored procedure returns a value larger than the maximum value of the data type for the value passed in, the system returns an overflow error.

For example, consider an external stored procedure that defines an INTEGER INOUT parameter:

CREATE PROCEDURE inout_example( INOUT p1 INTEGER )
LANGUAGE JAVA
READS SQL DATA
PARAMETER STYLE JAVA
EXTERNAL NAME 'NumJAR:NumClass.inout_example';

If you call the external stored procedure with a constant input value that fits into a SMALLINT, the system returns an overflow error if the output value is larger than 32767, the maximum value of a SMALLINT:

CALL inout_example(1000);