DEV Community

Cover image for How to count newest entries created in an oracle database
Adrian Matei for Codever

Posted on β€’ Edited on β€’ Originally published at codever.dev

3 2

How to count newest entries created in an oracle database

We will base the logic around sysdate which returns the current datetime, from which we substract different units. For example for the last day from now use sysdate - 1 (units default to day) and compare with the timestamp column (in this case CREATED_AT) :

select count(*)
from PARTNER
WHERE CREATED_AT > (sysdate - 1)

-- last 2 days would be
select count(*)
from PARTNER
WHERE CREATED_AT > (sysdate - 2)
Enter fullscreen mode Exit fullscreen mode

From the last hour, respectively last two hours use the following commands, where 1/24 is the unit for hour:

-- last hour
select count(*)
from PARTNER
WHERE CREATED_AT > (sysdate - 1/24)

-- last 2 hours
select count(*)
from PARTNER
WHERE CREATED_AT > (sysdate - 2/24)
Enter fullscreen mode Exit fullscreen mode

Shared with ❀️ from Codever. πŸ‘‰ use the copy to mine functionality to add it to your personal snippets collection.

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (2)

Collapse
 
erikpischel profile image
Erik Pischel β€’

"last hour" example is wrong. Should be 1/24.

Also: nice post

Collapse
 
ama profile image
Adrian Matei β€’

Thanks Erik, missed that :)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free β†’

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay