TO_DSINTERVAL
Purpose
Converts string_value specified as either of the following:
into an INTERVAL DAY(4) TO SECOND(6) value.
Any value that overflows the INTERVAL DAY(4) TO SECOND(6) 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_DSINTERVAL 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:
string_value Formats
The format for an interval day to second is [+ | -]DD HH:MM:SS[.xxxxxx]. One or more spaces separate the day from hour element. There can be any number of spaces between elements. DD is an integer between 0 and 9999, HH is an integer between 0 and 23, MM is an integer between 0 and 59, and SS is an integer between 0 and 59. The optional fractional seconds can be from .0 to .999999.
The format for a duration is [-]P[n]DT[n]H[n]M[n][.frac_secs]S where n specifies the value of the element (for example, 4H is 4 hours). This represents a subset of the ISO duration format and any other duration letters (including valid ISO letters such as Y and M) result in an error.
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 is used to denote 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. Fractional seconds are optional and can be between .0 and .999999.
The T designator always precedes the time elements (and removes the ambiguity of M between months and minutes within the full ISO duration syntax). If there are no H, M, or S time elements, T is omitted.
Values can exceed their normal time limit. For example, PT72H represents 72 hours even though there are 24 hours in a day. The ISO duration letter designators have the following meaning (only the P, D, T, H, M, and S designators are allowed for the DAY to SECONDS interval):
ISO Designator |
Definition |
P |
Duration. It is always at the beginning. |
D |
Day. It follows the number of days. |
T |
Time. It precedes the time elements H, M, and S. |
H |
Hour. It follows the number of hours. |
M |
Minutes. It follows the number of minutes. |
S |
Second. It follows the number of seconds. |
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 DAY(4) TO SECOND(6).
Example
The following query, which specifies an SQL interval format:
SELECT TO_DSINTERVAL('100 04:23:59');
returns the result '100 04:23:59.000000'.
Example
The following query, which specifies an SQL interval format:
SELECT TO_DSINTERVAL('100 04:23:59.543');
returns the result '100 04:23:59.543000'.
Example
The following query, which specifies an ISO duration:
SELECT TO_DSINTERVAL('P100DT4H23M59S');
returns the result '100 04:23:59.000000'.
Example
The following query, which specifies an ISO duration of 73 hours:
SELECT TO_DSINTERVAL('PT73H');
returns the result '3 01:00:00.000000', which is 3 days, 1 hours.
Example
The following query:
SELECT TO_DSINTERVAL('P2MT12H');
returns an error because the month designator, '2M', isn't allowed.