Oracle 顶点中的数据

Data in Oracle apex

如果我想获取今天从 00:00 到当前时间的数据,我该怎么做??? 我有这个 table

datetime hourly clientchannel servicename service_count
13_02_2022 9 ***** notification 2

假设datetime列的数据类型是DATE(应该是),那么

select *
from your_table
where datetime between trunc(sysdate) and trunc(sysdate, 'hh24')

因为

SQL> alter session set nls_date_format = 'dd.mm.yyyy hh24:mi:ss';

Session altered.

SQL> select sysdate as right_now,
  2    trunc(sysdate) as midnight,
  3    trunc(sysdate, 'hh24') this_hour
  4  from dual;

RIGHT_NOW           MIDNIGHT            THIS_HOUR
------------------- ------------------- -------------------
01.03.2022 08:01:20 01.03.2022 00:00:00 01.03.2022 08:00:00

SQL>

如果 datetime 的数据类型是 VARCHAR2(错误的选择),那么您应该首先将其转换为日期,应用正确的格式模型并希望该列中没有垃圾:

where to_date(datetime, 'dd_mm_yyyy') between ...