Oracle Extract Functions

Source: Internet
Author: User

Oracle's Extract function // The extract () function in oracle is introduced from oracle 9i. It is used to Extract a specific part from a date or interval type. // The syntax is as follows:

EXTRACT ({YEAR | MONTH | DAY | HOUR | MINUTE | SECOND} | {TIMEZONE_HOUR | TIMEZONE_MINUTE} | {TIMEZONE_REGION | TIMEZONE_ABBR} FROM {date_value | interval_value }) // We can only extract year, month, and day from a date type (the date format is yyyy-mm-dd ); // We can only extract TIMEZONE_HOUR and TIMEZONE_MINUTE from a timestamp with time zone data type; select extract (year from date '2017-05-17 ') year from dual; YEAR ---------- 2011 select extract (month from date '2014-05-17 ') month from dual; MONTH ---------- 5 select extract (day from date '2014-05-17') day from dual; DAY ---------- 17 // get the exact interval between two dates, the extract function is the best choice for select extract (day from dt2-dt1) day, extract (hour from dt2-dt1) hour, extract (minute from dt2-dt1) minute, extract (second from dt2-dt1) second from (select to_timestamp ('2017-02-04 15:07:00 ', 'yyyy-mm-dd hh24: mi: ss ') dt1, to_timestamp ('2017-05-17 19:08:46', 'yyyy-mm-dd hh24: mi: ss') dt2 from dual) /day hour minute second ---------- 102 4 1 46 -- select extract (year from week imestamp) year, extract (month from week imestamp) month, extract (day from week imestamp), day, extract (minute from Alibaba imestamp) minute, extract (second from Alibaba imestamp) second, extract (distinct from nation) th, extract (distinct from Alibaba imestamp) tm, extract (distinct from Alibaba imestamp, extract (distinct from begin imestamp) ta from dual/year month day minute second th tm tr ta ---------- ----------- ---------- 2011 5 17 7 14.843 8 0 unknown unk //


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.