Oracle sample query to grab one week's data

Posted on 2011-10-11
Last Modified: 2012-05-12

Can anyone let me know a sample query to pull data for a week

from last Monday to this Monday
Question by:new_perl_user
    LVL 76

    Expert Comment

    by:slightwv (䄆 Netminder)
    select * from table_name where
    date_column >= to_date('10/03/2011','MM/DD/YYYY') and date_column < to_date('10/11/2011','MM/DD/YYYY');

    Author Comment

    something without  hard coding the date because it goes into an automated script. For the above one I need to change date always.
    LVL 76

    Accepted Solution

    You can use sysdate as long as you know when it runs:

    select * from table where date_column >= trunc(sysdate)-7 and date_column < trunc(sysdate)+1
    LVL 34

    Expert Comment

    I would use the NEXT_DAY function.

    select * from table where date_column >= next_day(sysdate, 'MONDAY') - 14 and
    date_column < next_day(sysdate, 'MONDAY') - 7;

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
    Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
    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 videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

    729 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

    24 Experts available now in Live!

    Get 1:1 Help Now