Purpose
NUMTOYMINTERVAL() adds an interval unit to a numeric expression to convert the expression to a value of the INTERVAL YEAR TO MONTH data type. This function can be used to perform addition and subtraction operations on a datetime value.
Syntax
NUMTOYMINTERVAL(number, 'interval_unit')
Parameters
| Parameter | Description |
|---|---|
| number | The number of intervals. It is a NUMBER value or an expression that can be implicitly converted to a NUMBER value. |
| interval_unit | The interval unit. It can be of the CHAR, VARCHAR2, NCHAR, or NVARCHAR2 data type. It is case-insensitive. By default, the precision of the return value is 9. The following interval units are supported:
|
Return type
The return type is INTERVAL YEAR TO MONTH.
Examples
The following example converts
6 MONTHto a value of theINTERVAL YEAR TO MONTHdata type.obclient> SELECT NUMTOYMINTERVAL(6,'MONTH') FROM DUAL; +----------------------------+ | NUMTOYMINTERVAL(6,'MONTH') | +----------------------------+ | +000000000-06 | +----------------------------+ 1 row in setReturn the date six months after the current date.
obclient> SELECT SYSDATE+NUMTOYMINTERVAL(6,'MONTH') FROM DUAL; +------------------------------------+ | SYSDATE+NUMTOYMINTERVAL(6,'MONTH') | +------------------------------------+ | 07-JUN-22 | +------------------------------------+ 1 row in set