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.
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!