15.00 - Numeric-to-INTERVAL Conversion - 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

Numeric-to-INTERVAL Conversion

Purpose

Convert numeric data to an INTERVAL value with a single DateTime field.

CAST Syntax

where:

 

Syntax element …

Specifies …

numeric_expression

an expression or existing field having a numeric data type.

interval_data_type

the target INTERVAL data type to which the numeric expression is being converted.

interval_data_attribute

one of the following optional data attributes:

  • NAMED
  • TITLE
  • ANSI Compliance

    This is ANSI SQL:2011 compliant.

    As an extension to ANSI, CAST permits the use of interval data attribute phrases.

    Teradata Conversion Syntax

    where:

     

    Syntax element …

    Specifies …

    numeric_expression

    an expression or existing field having a numeric data type.

    data_attribute

    one of the following optional data attributes:

  • NAMED
  • TITLE
  • interval_data_type

    the target INTERVAL data type to which the numeric expression is being converted.

    ANSI Compliance

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

    Usage Notes  

    Numeric data is converted to an INTERVAL value with a single DateTime field.

    If the numeric value is in the value range allowed for the INTERVAL, the value is used as the single field of the INTERVAL. Otherwise, an overflow error is returned.

    Implicit Numeric-to-INTERVAL Conversion

    Teradata Database performs implicit conversion of an exact numeric data type to an Interval data type in some cases. See “Implicit Conversion of DateTime types” on page 586.

    Example  

    The following query returns '   -5' (with three leading pad characters).

       SELECT CAST(-5 AS INTERVAL YEAR(4));

    Related Topics

    For details on data types and data attributes, see SQL Data Types and Literals.