Oracle this month, last month, last year

Source: Internet
Author: User

select trunc(sysdate, ‘month‘ ) 本月第一天,         trunc(last_day(sysdate)) 本月最后一天,         trunc(add_months(sysdate, -1), ‘month‘ ) 上月第一天,         trunc(last_day(add_months(sysdate, -1))) 上月最后一天,         trunc(add_months(sysdate, -12), ‘month‘ ) 去年本月第一天,         trunc(last_day(add_months(sysdate, -12))) 去年本月最后一天    from dual

Add_month (date, number) Use the date inside the month plus number to get a new date, if the number is negative you can get past month date last_day (date) Get the last day of the month
This is going to use the add_months () function parameter negative to represent the forward  positive representation of the future.
Select To_char (Add_months (Trunc (sysdate), -1), ' Yyyymm ') from dual;
--Last one months
Select To_char (Add_months (Trunc (sysdate), 1), ' Yyyymm ') from dual;
--Next one months

Oracle this month, last month, last year

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.