Two implementation methods for Oracle Database date range query

Source: Internet
Author: User

Oracle Database date range queryThere are two methods:To_charAndTo_date MethodNext, we will introduce this process through an instance. Suppose we want to query the data from to. The implementation method is as follows:

To_date method:

 
 
  1. select * from tablename where time>=  
  2. to_date('2011-05-02','yyyy-mm-dd')    
  3. and  time<=to_date('2011-05-30','yyyy-mm-dd') 

The running result is: The data of can be displayed, but the data of cannot be displayed.

All conclusions can be drawn:

① If you want to display data of 2011-30, you can <to_date ('1970-05-31 ', 'yyyy-mm-dd') to display the data of-30.

② If you want to display data of 2011-30, you can <= to_date ('2017-05-30 23:59:59 123', 'yyyy-mm-dd hh24: mi: ss.

To_char:

Query the preceding two dates.

 
 
  1. select * from tablename where to_char(time,'yyyy-mm-dd')>='2011-05-02'    
  2. and to_char(time,'yyyy-mm-dd')<='2011-05-30' 

Query Result: Data of and can be displayed simultaneously.

Here are two implementation methods for Oracle Database date range query: The to_date method and the to_char method. I hope this introduction will be helpful to you!

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.