Managing Data in Different Time Zones
Managing Data in Different Time Zones
Objectives
5-2
Time Zones
+07:00
-08:00
+02:00
+10:00
-05:00
An absolute offset
Database time zone
OS local time zone
A named region
ALTER
ALTER
ALTER
ALTER
5-4
SESSION
SESSION
SESSION
SESSION
SET
SET
SET
SET
TIME_ZONE
TIME_ZONE
TIME_ZONE
TIME_ZONE
=
=
=
=
'-05:00';
dbtimezone;
local;
'America/New_York';
CURRENT_DATE, CURRENT_TIMESTAMP,
and LOCALTIMESTAMP
CURRENT_DATE
Returns the current date from the system
Has a data type of DATE
CURRENT_TIMESTAMP
Returns the current timestamp from the system
Has a data type of TIMESTAMP WITH TIME ZONE
LOCALTIMESTAMP
Returns the current timestamp from user session
Has a data type of TIMESTAMP
5-5
CURRENT_DATE
Display the current date and time in the sessions time
zone.
ALTER SESSION
SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS';
ALTER SESSION SET TIME_ZONE = '-5:0';
SELECT SESSIONTIMEZONE, CURRENT_DATE FROM DUAL;
5-6
CURRENT_TIMESTAMP
5-7
LOCALTIMESTAMP
5-8
5-9
[(fractional_seconds_precision)]_
TIMESTAMP
[(fractional_seconds_precision)]_
[(fractional_seconds_precision)]_
WITH LOCAL TIME ZONE
5-10
Data Type
5-11
Fields
TIMESTAMP
TIMESTAMP Fields
5-12
Datetime Field
Valid Values
YEAR
MONTH
01 to 12
DAY
01 to 31
HOUR
00 to 23
MINUTE
00 to 59
SECOND
TIMEZONE_HOUR
12 to 14
TIMEZONE_MINUTE
00 to 59
-- when hire_date is
of type DATE
SELECT hire_date
FROM emp5;
SELECT hire_date
FROM emp5;
5-13
TIMESTAMP[(fractional_seconds_precision)]
WITH TIME ZONE
5-14
5-15
TIMESTAMP[(fractional_seconds_precision)]
WITH LOCAL TIME ZONE
5-16
5-17
5-18
Data Type
Fields
Year, Month
INTERVAL Fields
5-20
INTERVAL Field
YEAR
MONTH
00 to 11
DAY
HOUR
00 to 23
MINUTE
00 to 59
SECOND
For example:
5-21
5-22
For example:
INTERVAL '6 03:30:16' DAY TO SECOND
Indicates an interval of 6 days 3 hours 30 minutes
and 16 seconds
INTERVAL '6 00:00:00' DAY TO SECOND
Indicates an interval of 6 days and 0 hours,
minutes and 0 seconds
5-23
TO SECOND);
5-24
EXTRACT
5-25
TZ_OFFSET
5-26
5-28
Display the character string '1999-12-01 11:00:00 8:00' as a TIMESTAMP WITH TIME ZONE value.
SELECT
TO_TIMESTAMP_TZ('1999-12-01 11:00:00 -8:00',
'YYYY-MM-DD HH:MI:SS TZH:TZM')
FROM DUAL;
5-29
5-30
5-31
5-32
Summary
5-34
Practice 5: Overview
5-35