NUMTOYMINTERVAL

NUMTOYMINTERVAL is an Oracle SQL function that converts a number to an interval of year-month type. It is primarily used to handle arithmetic operations and comparisons of periods that involve years and months.

NUMTOYMINTERVAL(n, ‘interval_unit’)

  • n: This is the first parameter of the NUMTOYMINTERVAL function, representing the number. It converts this numeric value into an “interval year to month” datatype.
  • ‘interval_unit’: This is the second parameter of the NUMTOYMINTERVAL function. It specifies the unit of the interval such as ‘YEAR’ or ‘MONTH’. The function uses this parameter to interpret the numeric value.

Example

SELECT NUMTOYMINTERVAL(2, 'YEAR') FROM dual;

Output

+------------------------+
| NUMTOYMINTERVAL(2,YEAR)|
+------------------------+
| +02-00 |
+------------------------+

Explanation

The NUMTOYMINTERVAL function in Oracle SQL is used to convert a number to a year-month INTERVAL. In this example, the function converts the number 2 into an interval of 2 years. The output “+02-00” represents “2 years and 0 months”.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.