Lola
Lola

Reputation: 21

Charts in Oracle Apex

Hi everyone I wanna ask u about how I can bring data last 24 hours into bar charts, is there any methods to make it please I have this table without data

datetime clientchannel servicename service_count
13_02_2022 9:35 ***** notification 2

Upvotes: 0

Views: 125

Answers (1)

Littlefoot
Littlefoot

Reputation: 142705

It is a WHERE clause you need, I presume. Something like this:

select ...
from your_table
where datetime >= sysdate - 1;

Why? Because - when you subtract a number from DATE datatype value in Oracle - it subtracts that many days.

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

Session altered.

SQL> select sysdate right_now,
  2         sysdate - 1 yesterday
  3  from dual;

RIGHT_NOW           YESTERDAY
------------------- -------------------
13.02.2022 11:01:34 12.02.2022 11:01:34

SQL>

If you store date values as strings (which means that DATETIME column is declared as e.g. VARCHAR2(20), and that's really bad idea), then you first have to convert it to a valid date datatype value - use TO_DATE function with appropriate format mask:

where to_date(datetime, 'dd_mm_yyyy hh24:mi') >= sysdate - 1

[EDIT] If you want to go 60 minutes back, then subtract that many minutes:

SQL> select sysdate right_now,
  2         sysdate - interval '60' minute an_hour_ago
  3  from dual;

RIGHT_NOW           AN_HOUR_AGO
------------------- -------------------
14.02.2022 07:09:30 14.02.2022 06:09:30

SQL>

Upvotes: 1

Related Questions