Solved

HOW TO SELECT ROWS WHERE THE TIMESTAMP COLUMN = CURRENT DATE - 1

Posted on 2008-11-03
3
1,081 Views
Last Modified: 2012-08-13
I need to perform a select and manipulate the where clause like so:

SELECT * FROM MY_TABLE WHERE MY_TIMESTAMP = CURRENT_DATE - 1

the date being at the level of a DAY (not hours or whatever)

anyone know how this is done in Oracle?
0
Comment
Question by:const71
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 22868041
this will do:
SELECT * FROM MY_TABLE WHERE MY_TIMESTAMP >= TRUNC(SYSDATE) - 1 AND MY_TIMESTAMP < TRUNC(SYSDATE) 

Open in new window

0
 
LVL 34

Expert Comment

by:Mark Geerlings
ID: 22868355
Or this:

SELECT * FROM MY_TABLE WHERE MY_TIMESTAMP between trunc(SYSDATE) - 2 and trunc(SYSDATE) -1;

This can also work, but performance could be terrible:

SELECT * FROM MY_TABLE WHERE trunc(MY_TIMESTAMP) = trunc(SYSDATE - 1);

If the table is large, and if it is indexed on this column, this query will *NOT* be able to use the index, so my first suggestion, or angellll's suggestion will allow index(es) to be used.
0
 

Author Closing Comment

by:const71
ID: 31512737
Absolutely awesome..Thanks!!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Oracle SQL Syntax 8 57
oracle rollup query 3 37
dates - loop 12 41
Best RAID for a BDD Oracle 4 18
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now