Home > Database > Oracle > body text

What are the queries with date as condition in Oracle?

coldplay.xixi
Release: 2020-07-16 11:15:08
Original
5966 people have browsed it

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');
Copy after login

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');
Copy after login

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

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

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;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!