Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-11-03
3
Medium Priority
?
1,088 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Via a live example, show how to take different types of Oracle backups using RMAN.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

704 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