 |
|
EnterpriseDB: INTERVAL
Oracle Tips by Burleson Consulting
|
An
interval is a period of time, like the time it takes you to leave
your house and the time it takes you to drive to work is an interval
of time. An interval is the difference between a starting
point in time and an ending point in time (my, how 4th
dimensional!).
Intervals also (like a timestamp) accept an optional precision of
1-6. That precision determines the granularity of the unit
chosen. The available units of time are: second, minute,
hour, day, week, month, year, decade, century, or millennium.
A
date, let's say 01-JAN-2006 added to INTERVAL '1 YEAR', DATE
'01-JAN-2006' + INTERVAL '1 YEAR', would equal 01-JAN-2007.
That same date added to INTERVAL '6 MONTHS' would equal 01-JUL-2006.
The
uses of INTERVAL are somewhat limited. I have rarely needed
them and had they not been available, I could have made do with a
NUMBER field or a DATE field. I would recommend that you not
use INTERVAL unless migrating an application that uses it already.
There
are no synonyms for interval.
CREATE TABLE date_table (
date_field DATE,
ts_field TIMESTAMP(6),
int_field INTERVAL );
We can
insert some values:
INSERT INTO date_table ( date_field, ts_field,
int_field )
VALUES (to_date('01-JAN-2007 12:33:54', 'DD-MON-YYYY HH24:MI:SS'),
to_timestamp('01-JAN-2007
12:33:54.123456',
'DD-MON-YYYY HH24:MI:SS.us'),
INTERVAL '1 Year' );
*
EnterpriseDB does not support the .ff fractional seconds syntax that
Oracle supports. It does not produce an error but only returns
a 0. Use .ms for milliseconds and .us for microsends.
And we
can select those values back out:
SELECT date_field, ts_field, int_field
FROM date_table;
edb=# CREATE TABLE date_table (
edb(# date_field DATE,
edb(# ts_field TIMESTAMP(6),
edb(# int_field INTERVAL );
CREATE TABLE
edb=# INSERT INTO date_table ( date_field, ts_field, int_field )edb-#
VALUES (to_date('01-JAN-2007 12:33:54', 'DD-MON-YYYY HH24:MI:SS'),
edb(#
to_timestamp('01-JAN-2007 12:33:54.123456',
edb(#
'DD-MON-YYYY HH24:MI:SS.us'),
edb(#
INTERVAL '1 Year' );
INSERT 0 1
edb=# SELECT date_field, ts_field, int_field
edb-# FROM date_table;
date_field
| ts_field
| int_field
--------------------+---------------------------+-----------
01-JAN-07 12:33:54 | 01-JAN-07 12:33:54.123456 | @ 1 year
(1 row)
edb=#
Binary
Data
Binary
data is data that is not interpreted by the database. For
example, a string of data, let's use "Lewis" as an example, is
stored as 1s and 0s on the physical disk but the database interprets
those 1s and 0s so that it comes out "Lewis". If you switched
to a different language, you could translate that word into its
foreign language counterpart. This is known as having a
locale.
A
digital image is a binary file. The data would be stored as 1s
and 0s and the database would never try to interpret what those 1s
and 0s mean. If you switched to another language, it would
still just be 1s and 0s. Binary data has no locale.
This
is an excerpt from the book "EnterpriseDB:
The Definitive Reference" by Rampant TechPress.