Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-11-03
3
Medium Priority
?
1,089 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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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 35

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to recover a database from a user managed backup
Suggested Courses

971 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