Solved

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

Posted on 2008-11-03
3
1,082 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help with Oracle syntax 4 56
oracle query help 29 77
T-SQL Convert to PL/SQL 23 77
export Oracle diagram from Oracle DB including VIEWS 8 102
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

910 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

22 Experts available now in Live!

Get 1:1 Help Now