Les 05
Les 05
• CURRENT_DATE, CURRENT_TIMESTAMP,
and LOCALTIMESTAMP
• INTERVAL data types
• Using the following functions:
– EXTRACT
– TZ_OFFSET
– FROM_TZ
– TO_TIMESTAMP
– TO_YMINTERVAL
– TO_DSINTERVAL
-08:00 +07:00
+02:00 +10:00
-05:00
ALTER SESSION
SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS';
ALTER SESSION SET TIME_ZONE = '-5:00';
SELECT SESSIONTIMEZONE, CURRENT_DATE FROM DUAL;
SELECT SESSIONTIMEZONE, CURRENT_TIMESTAMP FROM DUAL;
SELECT SESSIONTIMEZONE, LOCALTIMESTAMP FROM DUAL;
TIMESTAMP WITH TIME ZONE Same as the TIMESTAMP data type; also
includes:
TIMEZONE_HOUR, and TIMEZONE_MINUTE
or TIMEZONE_REGION
A B
-- when hire_date is ALTER TABLE employees
of type DATE MODIFY hire_date TIMESTAMP;
…
5 - 12 Copyright © 2007, Oracle. All rights reserved.
Comparing TIMESTAMP Data Types
• CURRENT_DATE, CURRENT_TIMESTAMP,
and LOCALTIMESTAMP
• INTERVAL data types
• Using the following functions:
– EXTRACT
– TZ_OFFSET
– FROM_TZ
– TO_TIMESTAMP
– TO_YMINTERVAL
– TO_DSINTERVAL
MONTH 00 to 11
HOUR 00 to 23
MINUTE 00 to 59
• CURRENT_DATE, CURRENT_TIMESTAMP,
and LOCALTIMESTAMP
• INTERVAL data types
• Using the following functions:
– EXTRACT
– TZ_OFFSET
– FROM_TZ
– TO_TIMESTAMP
– TO_YMINTERVAL
– TO_DSINTERVAL
SELECT TZ_OFFSET('US/Eastern'),
TZ_OFFSET('Canada/Yukon'),
TZ_OFFSET('Europe/London')
FROM DUAL;
SELECT FROM_TZ(TIMESTAMP
'2000-07-12 08:00:00', 'Australia/North')
FROM DUAL;
Display a date that is one year and two months after the hire
date for the employees working in the department with the
DEPARTMENT_ID 20.
SELECT hire_date,
hire_date + TO_YMINTERVAL('01-02') AS
HIRE_DATE_YMININTERVAL
FROM employees
WHERE department_id = 20;
Display a date that is 100 days and 10 hours after the hire date
for all the employees.
SELECT last_name,
TO_CHAR(hire_date, 'mm-dd-yy:hh:mi:ss') hire_date,
TO_CHAR(hire_date +
TO_DSINTERVAL('100 10:00:00'),
'mm-dd-yy:hh:mi:ss') hiredate2
FROM employees;