Daily collection and collation of Oracle TRUNC function processing date format (very practical) _oracle

Source: Internet
Author: User
Tags current time

This article to share the Oracle trunc function processing date format related knowledge, very has the reference value, concrete please see below explanation.

Copy Code code as follows:

Select To_char (sysdate, ' Yyyy-mm-dd hh24:mi:ss ') from dual; --Show Current time

2011-12-29 16:24:34

Copy Code code as follows:

Select Trunc (Sysdate, ' year ') from dual; --Interception to year (first day of this year)

2011-1-1

Copy Code code as follows:

Select Trunc (sysdate, ' Q ') from dual; --intercept to quarter (first day of this quarter)

2011-10-1

Copy Code code as follows:

Select Trunc (sysdate, ' month ') from dual; --Interception to month (first day of this month)

2011-12-1

Copy Code code as follows:

Select Trunc (sysdate, ') from dual;

Empty

Copy Code code as follows:

Select To_char (trunc (sysdate), ' Yyyymmdd Hh24:mi:ss ') from dual; --The default interception to the day (0 minutes 0 seconds of the day)

20111229 00:00:00

Copy Code code as follows:

Select Trunc (sysdate-1, ' W ') from dual; --The nearest Thursday to the current time, if the day is Thursday, return the same day, otherwise return to Thursday

2011-12-22

Copy Code code as follows:

Select Trunc (sysdate, ' WW ') from dual; --Interception to last weekend (last Saturday)

2011-12-24

Copy Code code as follows:

Select Trunc (sysdate, ' Day ') from dual; --Intercept to week (the first day of this week, that is, Sunday)

2011-12-25

Copy Code code as follows:

Select Trunc (sysdate, ' IW ') from dual; --On the 2nd day of this week, this Monday

2011-12-26

Copy Code code as follows:

Select To_char (trunc (sysdate, ' DD '), ' YYYYMMDD hh24:mi:ss ') from dual;--intercept to day (0 minutes 0 seconds of the day)

20111229 00:00:00

Copy Code code as follows:

Select Trunc (sysdate, ' hh24 ') from dual; --intercept to hour (current hour, 0 minutes 0 seconds)

2011-12-29 16:00:00

Copy Code code as follows:

Select Trunc (sysdate, ' mi ') from dual; --intercept to minute (current minute, 0 seconds)

2011-12-29 16:24:00

Copy Code code as follows:

Select Trunc (sysdate, ' SS ') from dual;--error, no format accurate to second

About Oracle trunc function processing date format This is the end, I hope you like it.

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: 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.