numtodsinterval function usage

numtodsinterval (<x>, <C>)  , x is a number, c is a string that
indicates that the unit of x, x into the function of this interval day to second data type
Common units ( 'day', 'hour', 'minute', 'second')
example
SQL> select sysdate,sysdate+numtodsinterval(3,'hour') as res from dual;
SYSDATE             RES ------------------- -------------------

2019-10-09 09:52:07 2019-10-09 06:52:07

 
numtoyminterval  similar numtodsinterval function, into the x interval year to month data type
Common units 'year', 'month'
example
SQL> select sysdate,sysdate+numtoyminterval(3,'year') as res from dual;
SYSDATE             RES ------------------- -------------------

2019-10-09 09:54:12 2022-10-09 09:54:12

-----------------------------------------------------------------------------------------------------------------------

Format: NumToYMInterval (n, interval_unit);
n: Value Type
One expression of 'YEAR', 'MONTH', or may be converted to other two values: interval_unit
 
NumToYMInterval (1, 'YEAR'): one year after the interval
NumToYMInterval (-1, 'MONTH'): one month ago
 
Decimal places will be calculated as an integer, then a calculation:
 
select sysdate + numtoyminterval(0.1, 'MONTH')  as future from dual;
 
FUTURE
------------------
2019-11-09 09:54:37
 
The result of this function is: "INTERVAL YEAR TO MONTH literal". You can not do arithmetic and numerical.
select 1 + NumToYMInterval(1, 'MONTH') from dual
Oracle will return an error.
 
When doing date arithmetic, this function is very useful. For example: one month after taking date:
select sysdate + NumToYMInterval(1, 'MONTH') from dual;

Guess you like

Origin www.cnblogs.com/wangchuanfu/p/11639805.html