Oracle EXTRACT Functions

Source: Internet
Author: User

Oracle example:
Select extract (year from sysdate) from dual; // return Current Year
Select extract (month from sysdate) from dual; // return Current Month
Select extract (day from sysdate) from dual; // return Current Day
Select extract (hour from sysdate) from dual; // Error
Select extract (hour from timestamp '2017-10-10 10:10:10 ') from dual; // Correct

Select extract (minute from sysdate) from dual; // Error
Select extract (minute from timestamp '2017-10-10 10:10:10 ') from dual; // Correct

The preceding sections describe how to use the EXTRACT () function. An important part is that extract extracts the year, month, day, And hour parts in different ways.
When the next parameter of FROM in EXTRACT (year from sysdate) is of the date type, you can EXTRACT the YEAR, month, and day. that is to say, when this parameter is of the date type, the year, month, and day can be extracted, but the hour and minute parts cannot be extracted. the extraction time must be followed by a TIMESTAMP and a time character.
Note that in (minute from timestamp '2017-10-10 10:10:10, if '2017-10-10 10:10:10 'is replaced by a date field and converted to a character type, this method is also incorrect.
For example (minute from timestamp to_date (to_char (date type, 'yyyy-MM-DD hh24: mi: ss'), 'yyyy-MM-DD hh24: mi: ss ')), this cannot be executed.

You can use the to_char () function to extract the \ part from the date field. For example, to_char (date type, 'hh24: mi ')

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: info-contact@alibabacloud.com 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.