15.00 - TO_YMINTERVAL - 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)

TO_YMINTERVAL

Purpose  

Converts string_value specified as either:

  • SQL interval format
  • ISO duration format
  • into an INTERVAL YEAR(4) TO MONTH value.

    Any value that overflows the INTERVAL(4) YEAR TO MONTH value results in an error.

    Syntax  

    where:

     

    Syntax element …

    Specifies …

    TD_SYSFNLIB

    the name of the database where the function is located.

    string_value

    a character argument.

    If string_value is an empty string or NULL, NULL is returned.

    ANSI Compliance

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

    Invocation

    TO_YMINTERVAL 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 one of the following data types:

    CHAR, VARCHAR

    string_value Formats

  • SQL Interval Format
  • The format for an interval year to month is [+ | -]YY-MM. YY is an integer between 0 and 9999, and MM is an integer between 0 and 11.

  • ISO Duration Format
  • The format for a duration is [-]P[n]Y[n]M[n] where n specifies the value of the element (for example, 4Y is 4 years).

    This represents a subset of the ISO duration format and the use of any arguments other than P, Y, and M are ignored. Leading and trailing zeroes are optional. Spaces are not allowed within the element format. Elements may be omitted if they are zero, but at least one element and its number is required.

    A leading negative sign denotes a negative interval. If omitted, the interval is positive. A positive sign is not allowed.

    Element values are integers between 0 and any value that will not cause an interval overflow. The values can exceed their normal time limit. For example, P14M represents 14 months, even though there are 12 months in a year. The ISO duration letter designators have the following meaning (only the P, Y, and M designators are allowed for the YEAR to MONTHS interval):

     

    ISO Designator

    Definition

    P

    Duration. It is always at the beginning.

    Y

    Year. It follows the number of years.

    M

    Month. It follows the number of months.

    You can also pass arguments with data types that can be converted to the above types using the implicit data type conversion rules that apply to UDFs.

    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 return value data type is INTERVAL YEAR(4) TO MONTH.

    Example  

    The following query, which specifies an SQL interval format:

    SELECT TO_YMINTERVAL('04-10'); 

    returns the result '04-10'.

    Example  

    The following query, which specifies an ISO duration:

    SELECT TO_YMINTERVAL('P100Y4M'); 

    returns the result '100-04', which is 100 years, 4 months.

    Example  

    The following query:

    SELECT TO_YMINTERVAL('P20Y3M4DT12H23M34.234S');

    returns an error because only the P, Y, and M designators are allowed.

    Example  

    The following query, which specifies an ISO duration of -14 months:

    SELECT TO_YMINTERVAL('-P14M'); 

    returns the result '-01-02', which is negative 1 year, 2 months.