Oracle obtains data for the current month of the current year.

Source: Internet
Author: User
In Oracle, we used whereto_char (t. t_created_tm,

Use where to_char (t. t_created_tm,

Oracle to get today's data, previously used to where to_char (t. t_created_tm, 'yyyy-MM-DD ') = to_char (SYSDATE, 'yyyy-MM-DD ');

This method is inefficient, and even if t. t_created_tm is indexed, the index cannot be used during query because it is compared after function encapsulation.

Here we will introduce how to use TRUNC (SYSDATE) = today to compare and filter data to get the results of today's data.

Select trunc (SYSDATE) from dual;
-- TRUNC (SYSDATE)

The following method is better.

SELECT * FROM TBL_STEP t where T.T _ CREATE_TM> = TRUNC (SYSDATE );

If the current year's data is retrieved

SELECT * FROM TBL_STEP t where T.T _ CREATE_TM> = TRUNC (SYSDATE, 'yyyy ');

Data for the current month

SELECT * FROM TBL_STEP t where T.T _ CREATE_TM> = TRUNC (SYSDATE, 'mm') AND T.T _ CREATE_TM <= LAST_DAY (SYSDATE)

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.