INTERVAL DAY TO SECOND

The data type of INTERVAL DAY TO SECOND stores a time interval in days and seconds. Its format is:

INTERVAL DAY[(days_precision)]TO SECOND[(seconds_precision)

days_precision, optional, is an integer from 0 to 9, the default is 2. seconds_precision, optional, is an integer from 0 to 9, the default is 6. The data type of INTERVAL DAY TO SECOND can store a positive or negative time interval.

An INTERVAL DAY TO SECOND literal value is defined in the following syntax:

INTERVAL '[+|-][d] [h[:m[:s]]]' [DAY[(days_precision)]])[TO HOUR | MINUTE | SECOND[(seconds_precision)]]

ValueOptionalDescroption
+optionalspecifies if the time interval is positive, the default is positive.
-optionalspecifies if the time interval is negative.
dNot optionalis the number of days.
hoptionalis the number of hours. TO HOUR must be set if days and hours are provided.
moptionalis the number of minutes. TO MINUTES must be set if days and minutes are provided.
soptionalis the number of seconds; TO SECOND must be set if days and seconds are provided.
days_precisionoptionalis the precision for the days. The default is 2.
seconds_precisionoptionalis the precision for the fractional seconds. The default is 6.

The following table shows some examples of day-to-second interval literals.

LiteralDescription
INTERVAL '1' DAYInterval of 1 days.
INTERVAL '1' HOURInterval of 1 hours.
INTERVAL '99' MINUTEInterval of 99 minutes.
INTERVAL '99' SECONDInterval of 99 seconds.
INTERVAL '1 2' DAY TO HOURInterval of 1 days 2 hours.
INTERVAL '1 2:34' DAY TO MINUTEInterval of 1 days 2 hours 34 minutes.
INTERVAL '1 2:34:56' DAY TO SECONDInterval of 1 days 2 hours 34 minutes 56 seconds.
INTERVAL '123 4:56:78.12' DAY(3)TO SECOND(2)Interval of 123 days 4 hours 56 minutes 78.12 seconds.
INTERVAL '1 2:00:45' DAY TO SECONDInterval of 1 days 2 hours 0 minutes 45 seconds.
INTERVAL '-1 2:34:56' DAY TO SECONDNegative interval of 1 days 2 hours 34 minutes 56 seconds.

The following INTERVAL literal is invalid because the number of digits in the days exceeds the specified:

INTERVAL '1234 2:25:45' DAY(3) TO SECOND

CREATE TABLE myTable(
id       INTEGER,
duration INTERVAL DAY(3) TO SECOND (4)
);
INSERT INTO myTable(id, duration)VALUES (1, INTERVAL '1' DAY);
INSERT INTO myTable(id, duration)VALUES (2, INTERVAL '1' HOUR);
INSERT INTO myTable(id, duration)VALUES (3, INTERVAL '99' MINUTE);
INSERT INTO myTable(id, duration)VALUES (4, INTERVAL '9' SECOND);
INSERT INTO myTable(id, duration)VALUES (5, INTERVAL '1 2:34' DAY TO MINUTE);
INSERT INTO myTable(id, duration)VALUES (6, INTERVAL '1 2:34:56' DAY TO SECOND);

SQL> SELECT * FROM myTable;

        ID           DURATION
---------------------------------------------------
         1 +001 00:00:00.0000
         2 +000 01:00:00.0000
         3 +000 01:39:00.0000
         4 +000 00:00:09.0000
         5 +001 02:34:00.0000
         6 +001 02:34:56.0000

6 rows selected.

SQL>
Home »
Oracle »
Data types » 

Time_intervals:
  1. Time intervals
  2. INTERVAL YEAR TO MONTH
  3. INTERVAL DAY TO SECOND
Related: