Solved

ORACLE previous week date function

Posted on 2012-03-14
3
1,020 Views
Last Modified: 2012-03-15
I'd like to create a report which will run every Monday morning showing data for the previous week; Sun - Sat.

CLOSED_DTTM > trunc(SYSDATE)- 7 is not working.

What should I use?

Thanks.
0
Comment
Question by:saved4use
[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 20

Accepted Solution

by:
flow01 earned 500 total points
ID: 37722881
WHERE CLOSED_DDTM >=  trunc(sysdate - 7,'WW')
AND    CLOSED_DDTM <  trunc(sysdate,'WW')

The WW truncation gives as start of the week: sunday 00.00 hrs
0
 

Author Comment

by:saved4use
ID: 37723006
Will the above work even when, say,  the middle of the week is a new month?
0
 
LVL 16

Expert Comment

by:Wasim Akram Shaik
ID: 37723391
yes author, the solution which flow01 will work fine even in case the middle of week is a new month...

what in actual it does it, it truncates the day to start of the week,..

for example 01/Mar/2012 is thursday,

select trunc(to_date('01-Mar-2012','DD-Mon-YYYY'),'WW') from dual

this will result in 26th Feb 2012, which is start of the week and by default the start of week in oracle is sunday..
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
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…
Suggested Courses

623 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