Purpose
The NUMTOYMINTERVAL function converts a numeric expression into an INTERVAL YEAR TO MONTH value. This function is useful for adding or subtracting intervals from date and time values.
Syntax
NUMTOYMINTERVAL(number, 'interval_unit')
Parameters
Parameter |
Description |
|---|---|
| number | The number of intervals. This can be a NUMBER value or an expression that can be implicitly converted to a NUMBER value. |
| interval_unit | The unit of the interval. This can be a value of the CHAR, VARCHAR2, NCHAR, or NVARCHAR2 data type, and it is case-insensitive. By default, the precision is 9. The interval unit can be one of the following:
|
Return type
INTERVAL YEAR TO MONTH
Examples
Convert
6 MONTHto anINTERVAL YEAR TO MONTHvalue.obclient> SELECT NUMTOYMINTERVAL(6,'MONTH') FROM DUAL; +----------------------------+ | NUMTOYMINTERVAL(6,'MONTH') | +----------------------------+ | +000000000-06 | +----------------------------+ 1 row in setReturn the date value 6 months from the current date.
obclient> SELECT SYSDATE+NUMTOYMINTERVAL(6,'MONTH') FROM DUAL; +------------------------------------+ | SYSDATE+NUMTOYMINTERVAL(6,'MONTH') | +------------------------------------+ | 07-JUN-22 | +------------------------------------+ 1 row in set
