Saturday, September 26, 2009

Extracts and returns the value of a specified datetime field from a datetime

-- Values That Can Be Extracted:

-- YEAR
-- MONTH
-- DAY
-- HOUR
-- MINUTE
-- SECOND
-- TIMEZONE_HOUR
-- TIMEZONE_MINUTE
-- TIMEZONE_REGION
-- TIMEZONE_ABBR

EXTRACT ( FROM )
SELECT EXTRACT(YEAR FROM DATE '2005-01-04') FROM dual;

CREATE TABLE extract_test (
person_id NUMBER(3),
hire_date TIMESTAMP WITH TIME ZONE)
TABLESPACE data_sml;

INSERT INTO extract_test VALUES (100, SYSTIMESTAMP+1);
INSERT INTO extract_test VALUES (200, SYSTIMESTAMP+34);

SELECT EXTRACT(TIMEZONE_HOUR FROM hire_date)
FROM extract_test

No comments: