TIME INTERVAL in Oracle

Understanding TIME INTERVAL Data Types in Oracle

INTERVAL YEAR TO MONTH and INTERVAL DAY TO SECOND are two data types added to store interval of two dates. They can be use both in SQL and PL/SQL. The syntax is as below:

INTERVAL YEAR[(year_precision)] TO MONTH
INTERVAL DAY[(day_precision)] TO SECOND[(fractional_seconds_precision)]

There are defaults for precision. Two digest for year and day and six digest for fractional seconds.

SQL>   SELECT INTERVAL '5-9' YEAR TO MONTH FROM DUAL
Result: +05-09
Cover a time interval of 5 years and 9 months

SQL>   SELECT INTERVAL '7 15:20:07.7' DAY TO SECOND FROM DUAL
Result: +07 15:20:07.700000
Cover a time interval of 7 days, 15 hours, 20 minutes, 7 seconds and 7 milliseconds.

SQL>   SELECT INTERVAL '7 15:20:07.7' DAY TO SECOND(1) FROM DUAL
Result: +07 15:20:07.7
Cover a time interval of 7 days, 15 hours, 20 minutes, 7 seconds and 7 milliseconds.


Comments

Popular posts from this blog

Configure IP address on Oracle Linux

Oracle Directory Object