NUMTOYMINTERVAL

2023-10-24 09:23:03  Updated

Purpose

You can call this function to add 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:
  • YEAR
  • MONTH

Return type

The return type is INTERVAL YEAR TO MONTH.

Examples

  • The following example converts 6 MONTH to a value of the INTERVAL YEAR TO MONTH data type.

    obclient> SELECT NUMTOYMINTERVAL(6,'MONTH') FROM DUAL;
    +----------------------------+
     NUMTOYMINTERVAL(6,'MONTH') 
    +----------------------------+
     +000000000-06 
    +----------------------------+
    1 row in set
    
  • The following example returns 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
    

Contact Us