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.

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

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 :)

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay