to_date('specified time format','yyyy-mm-dd hh24:mi: ss')"."/> to_date('specified time format','yyyy-mm-dd hh24:mi: ss')".">

Home >Database >Oracle >How to query data in oracle that is greater than a specified time

How to query data in oracle that is greater than a specified time

WBOY
WBOYOriginal
2022-05-25 10:25:1419953browse

In Oracle, you can use the select statement with the "to_date" function to query data greater than the specified time. The syntax is "select * from table name where column name> to_date('specified time format','yyyy- mm-dd hh24:mi:ss')".

How to query data in oracle that is greater than a specified time

The operating environment of this tutorial: Windows 10 system, Oracle 11g version, Dell G3 computer.

How to query data in oracle that is greater than the specified time

The query results require records in a certain column that are greater than a certain point in time.

-- tablename 表名
-- columnname 列名
 select * from tablename where columnname > to_date('2022:5:25 09:40:00','yyyy-mm-dd hh24:mi:ss');

Examples are as follows:

How to query data in oracle that is greater than a specified time

modifytime and create are both strings and need to be converted into time and compared with time; otherwise it will prompt that the text and characters are not the same match.

Expand knowledge:

For example: I want to check the data generated in a table from March 11, 2011 to March 24, 2011. The interval should be [2011-03-11 00:00:00, 2011-03-25 00:00:00)

-- that is, excluding the right 2011-03-25 00:00:00 The value at the time point!

-- So, please see the following:

How to query data in oracle that is greater than a specified time

-- View the data generated on the 24th of 2011

-- Method 1: Use... and ...

eygle@SZTYORA> select count(*) from t
2  where cdate>=to_date('2011-03-24','yyyy-mm-dd')
3    and cdate
COUNT(*)
----------
5

-- Method 2: Use between ... and ...

eygle@SZTYORA> select count(*) from t
2  where cdate between to_date('2011-03-24','yyyy-mm-dd')
3    and to_date('2011-03-25','yyyy-mm-dd');
COUNT(*)
----------
6
eygle@SZTYORA> select * from t
2  where cdate between to_date('2011-03-24','yyyy-mm-dd')
3    and to_date('2011-03-25','yyyy-mm-dd')
4  order by cdate;
CDATE
-------------------
2011-03-24 00:00:00
2011-03-24 02:03:45
2011-03-24 10:37:03
2011-03-24 20:55:17
2011-03-24 23:59:59
2011-03-25 00:00:00

6 rows have been selected.

-- It can be seen that the use of between ... and ... in the second method is wrong. It also includes the record of 2011-03-25 00:00:00!

Recommended tutorial: "Oracle Video Tutorial"

The above is the detailed content of How to query data in oracle that is greater than a specified time. 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