Professional Documents
Culture Documents
-08:00
+07:00
+02:00 -05:00
+10:00
The image represents the time for each time zone when Greenwich time is 12:00.
5-1
TIME_ZONE may be set to: An absolute offset Database time zone OS local time zone A named region
SESSION SESSION SESSION SESSION SET SET SET SET TIME_ZONE TIME_ZONE TIME_ZONE TIME_ZONE = = = = '-05:00'; dbtimezone; local; 'America/New_York';
5-2
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-3
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;
ALTER SESSION SET TIME_ZONE = '-8:0'; SELECT SESSIONTIMEZONE, CURRENT_DATE FROM DUAL;
5-4
CURRENT_TIMESTAMP
Display the current date and fractional time in the sessions time zone.
ALTER SESSION SET TIME_ZONE = '-5:0'; SELECT SESSIONTIMEZONE, CURRENT_TIMESTAMP FROM DUAL;
ALTER SESSION SET TIME_ZONE = '-8:0'; SELECT SESSIONTIMEZONE, CURRENT_TIMESTAMP FROM DUAL;
5-5
LOCALTIMESTAMP
Display the current date and time in the sessions time zone in a value of TIMESTAMP data type.
ALTER SESSION SET TIME_ZONE = '-5:0'; SELECT CURRENT_TIMESTAMP, LOCALTIMESTAMP FROM DUAL;
ALTER SESSION SET TIME_ZONE = '-8:0'; SELECT CURRENT_TIMESTAMP, LOCALTIMESTAMP FROM DUAL;
LOCALTIMESTAMP returns a TIMESTAMP value, whereas CURRENT_TIMESTAMP returns a TIMESTAMP WITH TIME ZONE value.
Copyright 2004, Oracle. All rights reserved.
5-6
5-7
[(fractional_seconds_precision)]_
[(fractional_seconds_precision)]_ [(fractional_seconds_precision)]_
WITH LOCAL TIME ZONE
5-8
5-9
5-10
5-11
5-12
CREATE TABLE web_orders (ord_id number primary key, order_date TIMESTAMP WITH TIME ZONE); INSERT INTO web_orders values (ord_seq.nextval, current_date); SELECT * FROM web_orders;
5-13
5-14
5-15
5-16
5-18
INTERVAL YEAR TO MONTH stores a period of time using the YEAR and MONTH datetime fields.
INTERVAL YEAR [(year_precision)] TO MONTH
For example:
5-19
CREATE TABLE warranty (prod_id number, warranty_time INTERVAL YEAR(3) TO MONTH); INSERT INTO warranty VALUES (123, INTERVAL '8' MONTH); INSERT INTO warranty VALUES (155, INTERVAL '200' YEAR(3)); INSERT INTO warranty VALUES (678, '200-11'); SELECT * FROM warranty;
5-20
For example:
INTERVAL '6 03:30:16' DAY TO SECOND
5-21
5-22
EXTRACT
Display the YEAR component from the SYSDATE.
SELECT EXTRACT (YEAR FROM SYSDATE) FROM DUAL;
Display the MONTH component from the HIRE_DATE for those employees whose MANAGER_ID is 100.
SELECT last_name, hire_date, EXTRACT (MONTH FROM HIRE_DATE) FROM employees WHERE manager_id = 100;
5-23
TZ_OFFSET
5-24
Display the TIMESTAMP value '2000-03-28 08:00:00' as a TIMESTAMP WITH TIME ZONE value.
SELECT FROM_TZ(TIMESTAMP '2000-03-28 08:00:00','3:00') FROM DUAL;
Display the TIMESTAMP value '2000-03-28 08:00:00' as a TIMESTAMP WITH TIME ZONE value for the time zone region 'Australia/North'.
SELECT FROM_TZ(TIMESTAMP '2000-03-28 08:00:00', 'Australia/North') FROM DUAL;
5-26
Display the character string '1999-12-01 11:00:00 8:00' as a TIMESTAMP WITH TIME ZONE value.
5-27
5-28
5-29
5-30
Summary
In this lesson, you should have learned how to use the following functions: CURRENT_DATE TZ_OFFSET CURRENT_TIMESTAMP FROM_TZ LOCALTIMESTAMP TO_TIMESTAMP TO_TIMESTAMP_TZ DBTIMEZONE SESSIONTIMEZONE TO_YMINTERVAL EXTRACT
5-32
Practice 5: Overview
5-33