Home  >  Article  >  Database  >  What are the queries with date as condition in Oracle?

What are the queries with date as condition in Oracle?

coldplay.xixi
coldplay.xixiOriginal
2020-07-16 11:15:086070browse

The queries with date as a condition in Oracle include: 1. Query of range date, the code is [where g_time between to_date()and to_date()]; 2. Query equal to a certain date; 3. Current date Data query for the first few days and the next few days.

What are the queries with date as condition in Oracle?

Queries with date as a condition in Oracle are:

1. Query with range date:

select * from goods
where g_time between
to_date('2018/12/26 10:01:59','yyyy-MM-dd hh:mi:ss')
and to_date('2018/12/26 10:05:17',' yyyy-MM-dd hh:mi:ss');

2. Query equal to a certain date:

select * from goods
where g_time=to_date('2018/12/26 10:05:17','yyyy-MM-dd hh:mi:ss');

3. The days before and after the current date Data query:

select * from goods
where g_time >= trunc(sysdate)-6  and < trunc(sysdate)-3;

Why use trunc(sysdate)

Because the current time is generally not exactly 0 o'clock, for example, the current time is 11 o'clock, -6 means starting from 11 o'clock 6 days ago

4. Query the product information on the third to last day of each month:

select g.* from goods g where g.g_time=last_day(g.g_time)-2;

Related learning recommendations: oracle database learning tutorial

The above is the detailed content of What are the queries with date as condition 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