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 Teradata Vantage™ - Data Types and Literals, B035-1143.
Behavior When Using NULL as a Literal Argument
The RETURNS NULL ON NULL INPUT and CALLED ON NULL INPUT options in the METHOD specification of the CREATE TYPE statement determine what happens if the NULL keyword is used as any of the input arguments.
|IF an input argument is NULL and the corresponding CREATE TYPE statement specifies …||AND the parameter style is …||THEN …|
|RETURNS NULL ON NULL INPUT||SQL or TD_GENERAL||the method is not evaluated and the result is always NULL.|
|CALLED ON NULL INPUT||SQL||the method is invoked with the appropriate indicators set to the null indication.|
|TD_GENERAL||an error is reported.|
If the METHOD specification in the CREATE TYPE statement does not specify either RETURNS NULL ON NULL INPUT or CALLED ON NULL INPUT, the default is CALLED ON NULL INPUT.
NULL as a literal argument is compatible with a parameter of any data type. For example, consider the following address UDT and map_it method:
CREATE TYPE address AS ( street VARCHAR(20), zip CHAR(5) ) NOT FINAL INSTANCE METHOD map_it( CHAR(4), INTEGER ) RETURNS INTEGER SPECIFIC mapit LANGUAGE C PARAMETER STYLE SQL DETERMINISTIC NO SQL; CREATE METHOD map_it( map_type CHAR(4), code INTEGER ) RETURNS INTEGER FOR address EXTERNAL NAME 'CS!map_it!udm_src/map_it.c!F!mapit';
You can successfully use the NULL keyword as any method argument:
CREATE TABLE locations( id INTEGER, details address ); SELECT details.map_it('4415', NULL) FROM locations; SELECT details.map_it(NULL, NULL) FROM locations;
Passing the NULL keyword as an argument to overloaded methods can result in errors unless Vantage can identify which method to invoke without ambiguity. For details, see Calling a Function That is Overloaded.
Overflow and Numeric Arguments
To avoid numeric overflow conditions, the C/C++ function should define a decimal 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 a instance method that takes a DECIMAL(2,0) argument:
CREATE TYPE circle AS ( x INTEGER, y INTEGER, radius INTEGER ) NOT FINAL INSTANCE METHOD smldec( DECIMAL(2,0) ) RETURNS INTEGER SPECIFIC smldec LANGUAGE C PARAMETER STYLE SQL DETERMINISTIC NO SQL; CREATE METHOD smldec( DECIMAL(2,0) ) RETURNS INTEGER FOR circle EXTERNAL NAME 'CS!smldec!udm_src/smldec.c!F!smldec';
Passing a number with a maximum of two digits is successful:
SELECT circle_column.smldec(99) FROM circle_tbl WHERE c_id = 100;
An attempt to pass a number larger than 99 or smaller than -99 would result in a loss of significant digits.
SELECT circle_column.smldec(100) FROM circle_tbl WHERE c_id = 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 Teradata rounding rules. For more information on rounding, see Teradata Vantage™ - Data Types and Literals, B035-1143.