interval function in oracle

前端 未结 2 1991
旧巷少年郎
旧巷少年郎 2021-02-08 03:47

Query:

SELECT INTERVAL \'300\' month,
       INTERVAL \'54-2\' year to month,
       INTERVAL \' 11:12:10.1234567\' hour to second 
  FROM DUAL;
<
相关标签:
2条回答
  • 2021-02-08 03:51

    INTERVAL is not a function it's a keyword that introduces an interval literal and such denotes a data type. Similar to what the literals DATE '2011-05-04' or TIMESTAMP '2011-05-04 17:18:19' are doing.

    Details about interval literals
    http://docs.oracle.com/cd/E11882_01/server.112/e41084/sql_elements003.htm#SQLRF00221
    http://docs.oracle.com/cd/E11882_01/server.112/e41084/expressions009.htm#SQLRF52084

    Details about the interval datatype:
    http://docs.oracle.com/cd/E11882_01/server.112/e41084/sql_elements001.htm#i128552

    0 讨论(0)
  • 2021-02-08 04:18

    Interval is a function which is used to deduct or add (days,years,months,hour,minutes and seconds) to the given date. interval '300' month : 25-0 Reason : 300/12(months) gives you quotient as 25 and remainder as 0 so the output will be 25-0

    interval '54-2' year to month : 54-2 Reason : As you have not mentioned any date it is giving as it is. if you use select sysdate + interval '54-2' year to month from dual; output will be : 1-12-2066

    sydate : 1-10-2012 so adding 54 to 12 = 66 and adding 2 months to oct which will be dec.

    Same with the last option as well.

    0 讨论(0)
提交回复
热议问题