Oracle TRUNC functions handle date formats, date types are useful for several SQL

Source: Internet
Author: User

Select To_char (sysdate, ' Yyyy-mm-dd hh24:mi:ss ') from dual; --Show Current time
2011-12-29 16:24:34

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

Select Trunc (sysdate, ' Q ') from dual; -Intercept to quarter (first day of the quarter)
2011-10-1

Select Trunc (sysdate, ' month ') from dual; -Interception to the month (first day of the month)
2011-12-1

Select Trunc (sysdate, ') from dual;
Empty

Select To_char (trunc (sysdate), ' Yyyymmdd Hh24:mi:ss ') from dual; --Default intercept to day (0 minutes and 0 seconds of the day)
20111229 00:00:00

Select Trunc (sysdate-1, ' W ') from dual; --The most recent Thursday from the current time, if the day is Thursday then return the same day, otherwise return to Thursday
2011-12-22

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

Select Trunc (sysdate, ' Day ') from dual; -Intercept to week (first day of the week, Sunday)
2011-12-25

Select Trunc (sysdate, ' IW ') from dual; 2nd Day of the week, this Monday
2011-12-26

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

Select Trunc (sysdate, ' hh24 ') from dual; --intercept to hours (current hour, 0 minutes 0 seconds)
2011-12-29 16:00:00

Select Trunc (sysdate, ' mi ') from dual; --intercept to points (current minute, 0 seconds)
2011-12-29 16:24:00

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

Oracle TRUNC functions handle date formats, date types are useful for several SQL

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.