Home  >  Article  >  Database  >  How to query date range in oracle

How to query date range in oracle

hzc
hzcOriginal
2020-06-08 13:32:547055browse

How to query date range in oracle

Oracle’s method for querying date range is:

There are two ways to query date range in Oracle database: to_char method and to_date method, next We introduce this process through an example. We assume that we want to query the data between 2011-05-02 and 2011-05-30. The implementation method is as follows:

to_date method:

select * from tablename where time>=  to_date('2011-05-02','yyyy-mm-dd')    
and  time<=to_date(&#39;2011-05-30&#39;,&#39;yyyy-mm-dd&#39;)

The result of the operation is: 05-02 can be displayed data, but the data from 05-30 cannot be displayed.

All can be concluded:

①If you want to display the data from 05-30, you can

②If you want to display the data from 05-30, you can also use <=to_date('2011-05-30 23:59:59 999','yyyy-mm-dd hh24:mi:ss') It can be found out.

to_char method:

Similarly query the above two dates

select * from tablename where to_char(time,&#39;yyyy-mm-dd&#39;)>=&#39;2011-05-02&#39; 
and to_char(time,&#39;yyyy-mm-dd&#39;)<=&#39;2011-05-30&#39;

Query results: The data of 05-02 and 05-30 can be displayed at the same time.

That’s all the relevant knowledge about the two implementation methods of Oracle database date range query: to_date method and to_char method. I hope this introduction can be helpful to you!

Recommended tutorial: "Oracle Tutorial"

The above is the detailed content of How to query date range in oracle. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn