Thoughts

10g (1) 11c (1) 11g (5) 12c (4) 3.0 (1) ApEx (4) Cloud (11) database (10) DBA (1) EBR (1) EC2 (2) education (3) ExaData (1) F2F (1) Forms (7) java (1) language (2) memorabilia (2) Metalink vs MOS (4) multi-cultural (3) on-line communities (1) oracle (7) performance (5) projects (1) reciproke (1) Reports (2) RUP (1) sales (2) services (5) silence (1) SOA (3) SQL Server (2) standards (6) Sun (1) support (6) W8 (1) WebLogic Server (5)

Friday, September 04, 2009

Time will tell

SYSDATE is sufficient?
Today almost every date is stored in type DATE. One thought is to keep it simple and stay with that approach. “It works today why think about it”.

This document describes facilities worth taking under consideration. There might be scenarios where the SYSDATE-approach is not enough.

Things could be so that if you set the DB-server in UTC and the database time in init.ora you are OK.

Decide on Date OR time
The first decision is date OR time? Remember

SELECT TRUNC(SYSDATE)FROM DUAL;

gives you the date only. Whilst

SELECT SYSDATE FROM DUAL;


will present you date and time. Essential in comparisons between DATE-variables, when the intention is to perform something a special date.

Datatypes for date and time


There are four data types for date and time available.






DatatypeDescription
DATE Date and time, prior to Oracle 8i the one and only. Reflects DATE and DATETIME in Oracle Forms.
TIMESTAMPDate and time, no respect to time zone. TIMESTAMP(0) equivalent to DATE.
Resolution: billionth of a second.
Default resolution: millionth of a second.
TIMESTAMP WITH TIME ZONE Date and time along with time zone
TIMESTAMP WITH LOCAL TIME ZONE Date and time (with fractions) along with time zone in DB local time zone.



PL/SQL-variables of this type “local” is regarded as session time zone.
Values transferred between DB-columns and PL/SQL-variables are converted from one time zone to the other.

What’s the date and time?
There are two ways of accessing server date and time.

SYSDATE (datatype DATE) the old fashion way, must be used since there are no other ways if you are using Oracle 8i.

SYSTIMESTAMP (TIMESTAMP) the new way that also gives you time zone.

There are three ways of getting the sessions date and time.

  • 1. CURRENT_DATE of type DATE.
  • 2. CURRENT_TIMESTAMP that is of type TIMESTAMP WITH TIME ZONE
  • 3. LOCALTIMESTAMP of type TIMESTAMP.

No comments: