Plsql_ Basic Series 4_ time interval interval

Source: Internet
Author: User

2014-12-08 Baoxinjian

I. Summary

The interval data type is used to store a time interval between two timestamps.

You can specify an interval between years and months, or days,hours,minuts,seconds.

Oracle supports two types of inteval, each of which is year-to-month and day-to-SECOND.

Each type contains leading field and trailing field. The main parameter defines the date or time to be computed, and the secondary parameter defines the minimum growth amount

Second, the grammar

1. Oracle Syntax

INTERVAL ' {integer | integer time_expr | time_expr} '

{{Day | HOUR | MINUTE} [(Leading_precision)]

| SECOND [(Leading_precision [, Fractional_seconds_precision])}

[To {day | HOUR | MINUTE | SECOND [(Fractional_seconds_precision)]}]

(1). The range of leading_precision values is 0 to 9, which is 2 by default. TIME_EXPR in the format: HH[:MI[:SS[.N]]] or MI[:SS[.N]] or SS[.N], N for microseconds.

(2). There are many similarities between this type and interval year to month, it is recommended to look at interval year to month before looking at the article.

2. Range values:

Hour:0 to 23

Minute:0 to 59

second:0 to 59.999999999

Third, case analysis

1. INTERVAL ' 5 ' Day (3) to HOUR

Means: 400 days 5 hours, 400 is 3 for precision, so "day (3)", note the default value is 2

2. INTERVAL ' 30.12345 ' SECOND (2,4)

Represents: 30.1235 seconds, because the local second precision is set to 4, to be rounded

3. Other

Select Date ' 2010-01-01 ' + interval ' + ' year from dual

Select Date ' 2010-01-01 ' + interval ' 123-2 ' year (4) to month from dual

Select Date ' 2010-01-01 ' + interval ' + ' month from dual

Select Date ' 2010-01-01 ' + Interval ' Day (2) from dual

Select Date ' 2010-01-01 ' + interval ' 1 2 ' day to hour from dual

Select Date ' 2010-01-01 ' + interval ' 1 2:3 ' day to minute from dual

Select Date ' 2010-01-01 ' + interval ' 1 2:3:4 ' day to second from dual

Select Date ' 2010-01-01 ' + interval ' 1 ' hour from dual

Select Date ' 2010-01-01 ' + interval ' 1:2 ' hour to minute from dual

Select Date ' 2010-01-01 ' + interval ' 1:2:3 ' hour to second from dual

Select Date ' 2010-01-01 ' + interval ' 1:2 ' minute to second from dual

Thanks and regards

Plsql_ Basic Series 4_ time interval interval

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.