Pages

Monday, September 2, 2013

Easily find records changed since midnight (Oracle RDBMS 9i+)

If you need to find all records in a table that have a timestamp column with today′s date, you might think you′d have to do some sort of subtraction with dates. Actually, all you need to do is truncate today′s date.

For example, the following displays 12:00 a.m. today:
select trunc(sysdate) from dual;

Now, suppose you have a table orders with column orders_updatetime of data type timestamp that your application updates with the current time whenever it updates the record.

You can find records updated since midnight with the following query:
SELECT * FROM orders
WHERE orders_updatetime >
(trunc(sysdate));




No comments:

Post a Comment

Note: Only a member of this blog may post a comment.