15.00 - TRUNC - Teradata Database

Teradata Database SQL Functions, Operators, Expressions, and Predicates

Product
Teradata Database
Release Number
15.00
Content Type
Programming Reference
Publication ID
B035-1145-015K
Language
English (United States)
Last Update
2018-09-24

TRUNC

Purpose  

Returns numeric_value truncated places_value places to the right or left of the decimal point.

Syntax  

where:

 

Syntax element …

Specifies …

TD_SYSFNLIB

the name of the database where the function is located.

numeric_value

a numeric argument.

places_value

the number of places to truncate. If not specified, numeric_value is truncated to 0 places by default.

ANSI Compliance

This is a Teradata extension to the ANSI SQL:2011 standard.

Invocation

TRUNC is an embedded services system function. For information on activating and invoking embedded services functions, see “Embedded Services System Functions” on page 24.

Argument Types and Rules

Expressions passed to this function must have the following data types:

  • numeric_value = BYTEINT, SMALLINT, INTEGER, BIGINT, DECIMAL/NUMERIC, FLOAT/REAL/DOUBLE PRECISION, or NUMBER
  • places_value = NUMBER
  • For the places_value argument, you can also pass values with data types that can be converted to INTEGER using the implicit data type conversion rules that apply to UDFs. Implicit type conversion is not supported for the numeric_value argument.

    Note: The UDF implicit type conversion rules are more restrictive than the implicit type conversion rules normally used by Teradata Database. If an argument cannot be converted to the required data type following the UDF implicit conversion rules, it must be explicitly cast.

    For details, see “Compatible Types” in SQL External Routine Programming.

    Result Type

    The result data type is the same type as that of the numeric_value argument. For example, if the data type of numeric_value is DECIMAL/NUMERIC, the return type is DECIMAL/NUMERIC with the same precision and scale as the numeric_value argument.

    For information on the default data type formats, see SQL Data Types and Literals.

    Usage Notes  

    TRUNC functions as follows:

  • It truncates places_value places to the right of the decimal point if places_value is positive.
  • It truncates (makes 0) places_value places to the left of the decimal point if places_value is negative.
  • It truncates to 0 places if places_value is zero or is omitted.
  • If numeric_value or places_value is NULL, the function returns NULL.
  • Examples  

    The following query returns the result 32.4500.

       SELECT TRUNC(32.4567, 2);

    The following query returns the result 30.0000.

       SELECT TRUNC(32.4567, -1);