Oracle Interval Function

Query:

SELECT INTERVAL '300' month, INTERVAL '54-2' year to month, INTERVAL ' 11:12:10.1234567' hour to second FROM DUAL; 

The output of the above query:

 +25-00,+54-02,+00 11:12:10.1234567 

Can someone explain to me how this query gives this conclusion, with an explanation of the interval function?

+7
source share
2 answers

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

Interval Literal Details
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 of interval data type:
http://docs.oracle.com/cd/E11882_01/server.112/e41084/sql_elements001.htm#i128552

+10
source

An interval is a function that is used to subtract or add (days, years, months, hours, minutes and seconds) to a specified date. interval '300' month: 25-0 Reason: 300/12 (months) gives you a coefficient of 25 and the remainder is 0, so the output will be 25-0

interval '54 -2 'from year to year: 54-2 Reason: since you did not specify any date that it gives, it is. if you use select sysdate + interval '54 -2 'from year to year from double; the output will be: 1-12-2066

sydate: 1-10-2012 therefore adding 54 to 12 = 66 and adding 2 months in October, which will be dec.

Same thing with the last option.

+6
source

All Articles