Using Time Intervals : Time Interval « SQL Data Types « Oracle PL/SQL Tutorial

Oracle PL/SQL Tutorial
1. Introduction
2. Query Select
3. Set
4. Insert Update Delete
5. Sequences
6. Table
7. Table Joins
8. View
9. Index
10. SQL Data Types
11. Character String Functions
12. Aggregate Functions
13. Date Timestamp Functions
14. Numerical Math Functions
15. Conversion Functions
16. Analytical Functions
17. Miscellaneous Functions
18. Regular Expressions Functions
19. Statistical Functions
20. Linear Regression Functions
21. PL SQL Data Types
22. PL SQL Statements
23. PL SQL Operators
24. PL SQL Programming
25. Cursor
26. Collections
27. Function Procedure Packages
28. Trigger
29. SQL PLUS Session Environment
30. System Tables Data Dictionary
31. System Packages
32. Object Oriented
33. XML
34. Large Objects
35. Transaction
36. User Privilege
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Oracle PL/SQL Tutorial » SQL Data Types » Time Interval 
10. 10. 1. Using Time Intervals

Examples of time intervals include

  1. 2 year 3 months
  2. 5 months
  3. C3 days 5 hours 16 minutes
  4. 1 day 7 hours
  5. C6 hours

Time Interval Types

  1. INTERVAL YEAR[(years_precision)] TO MONTH
  2. Stores a time interval measured in years and months.
  3. You can specify an optional precision by supplying years_precision.
  4. years_precision may be an integer from 0 to 9.
  5. The default precision is 2, which means you can store two digits for the years in your interval.
  6. You can store a positive or negative time interval.

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

  1. Stores a time interval measured in days and seconds.
  2. You can specify an optional precision for the days.
  3. A days_precision integer is from 0 to 9 (default is 2).
  4. You can also specify an optional precision for the fractional seconds.
  5. A seconds_precision integer is from 0 to 9 (default is 6).
  6. You can store a positive or negative time interval.

Using the INTERVAL YEAR TO MONTH Type

INTERVAL YEAR TO MONTH type stores time intervals measured in years and months.

SQL>
SQL> CREATE TABLE myTable (
  2    id INTEGER,
  3    duration INTERVAL YEAR(3TO MONTH
  4  );

Table created.

SQL>
SQL>
SQL> desc myTable;
 Name       Null?    Type
 -------------------------------------------------------------------------------------------
 ID                  NUMBER(38)
 DURATION            INTERVAL YEAR(3TO MONTH

SQL>
SQL> drop table myTable;

Table dropped.

A precision of 3 for the duration column means up to three digits may be stored for the year part of the interval.

An INTERVAL YEAR TO MONTH literal value:

INTERVAL '[+|-][y][-m]' [YEAR[(years_precision)])] [TO MONTH]

where

  1. + or - is an optional indicator that specifies whether the time interval is positive or negative (default is positive).
  2. y is the optional number of years for the interval.
  3. m is the optional number of months for the interval. If you supply years and months, you must include TO MONTH in your literal.
  4. years_precision is the optional precision for the years (default is 2).

Quote from:

Oracle Database 10g SQL (Osborne ORACLE Press Series) (Paperback)

# Paperback: 608 pages

# Publisher: McGraw-Hill Osborne Media; 1st edition (February 20, 2004)

# Language: English

# ISBN-10: 0072229810

# ISBN-13: 978-0072229813

10. 10. Time Interval
10. 10. 1. Using Time Intervals
10. 10. 2. interval type column
10. 10. 3. Format interval type column
10. 10. 4. Insert value to interval type column
10. 10. 5. Use TIMESTAMP in insert statement to add value to interval type column
10. 10. 6. INTERVAL '1' YEAR: Interval of 1 year
10. 10. 7. INTERVAL '11' MONTH: Interval of 11 months
10. 10. 8. INTERVAL '14' MONTH: Interval of 14 months (equivalent to 1 year 2 months)
10. 10. 9. INTERVAL '1-3' YEAR TO MONTH: Interval of 1 year 3 months
10. 10. 10. INTERVAL '0-5' YEAR TO MONTH: Interval of 0 years 5 months
10. 10. 11. INTERVAL '123' YEAR(3) TO MONTH: Interval of 123 years with a precision of 3 digits
10. 10. 12. INTERVAL '-1-5' YEAR TO MONTH: A negative interval of 1 year 5 months
10. 10. 13. INTERVAL '1234' YEAR(3):
10. 10. 14. Using the INTERVAL DAY TO SECOND Type
10. 10. 15. INTERVAL '3' DAY: Interval of 3 days
10. 10. 16. INTERVAL '2' HOUR: Interval of 2 hours
10. 10. 17. INTERVAL '25' MINUTE: Interval of 25 minutes
10. 10. 18. INTERVAL '45' SECOND: Interval of 45 seconds
10. 10. 19. INTERVAL '3 2:25:45' DAY TO SECOND: Interval of 3 days 2 hours 25 minutes 45 seconds
10. 10. 20. INTERVAL '123 2:25:45.12' DAY(3) TO SECOND(2): Interval of 123 days 2 hours 25 minutes 45.12 seconds; the precision for days is 3 digits and the precision for the fractional seconds is 2 digits
10. 10. 21. INTERVAL '3 2:00:45' DAY TO SECOND: Interval of 3 days 2 hours 0 minutes 45 seconds
10. 10. 22. INTERVAL '-3 2:25:45' DAY TO SECOND: Negative interval of 3 days 2 hours 25 minutes 45 seconds
10. 10. 23. INTERVAL '1234 2:25:45' DAY(3) TO SECOND: Invalid interval because the number of digits in the days exceeds the specified precision of 3
10. 10. 24. INTERVAL '123 2:25:45.123' DAY TO SECOND(2): Invalid interval because the number of digits in the fractional seconds exceeds the specified precision of 2
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.