Function to retrieve all the days of the previous month.
HelloYes, it's a monthly report, I received the task at hand.
So, all I need is every day of the previous month (even if there is no data for that day)
I was instructed to use the following code, but it does not return a value any:
DECLARE
CURSOR CUR_LAST_DAY IS
SELECT TO_CHAR (LAST_DAY (ADD_MONTHS (SYSDATE, -1) ), 'DD')
FROM DUAL;
VVA_LAST_DAY VARCHAR2 (2);
--
VNU_JOUR NUMBER := 0;
BEGIN
OPEN CUR_LAST_DAY;
FETCH CUR_LAST_DAY
INTO VVA_LAST_DAY;
CLOSE CUR_LAST_DAY;
WHILE VNU_JOUR <= TO_NUMBER (VVA_LAST_DAY) - 1
LOOP
VNU_JOUR := VNU_JOUR + 1;
END LOOP;
END;
--CLOSE CUR_LAST_DAY
--DEALLOCATE CUR_LAST_DAY
-----On the other end, I developed this code:
SELECT TO_CHAR(SYSDATE,'dd')
FROM DUAL
WHERE TO_CHAR(SYSDATE,'dd') >= to_char(to_date(to_char(ADD_MONTHS(SYSDATE, -1),'yyyy-mm')||'-01'),'yyyy-mm-dd')
AND TO_CHAR(SYSDATE,'dd') < to_char(LAST_DAY(to_date(to_date(to_char(ADD_MONTHS(SYSDATE, -1),'yyyy-mm')||'-01'),'yyyy-mm-dd')));
Which returns a null value. :(Concerning
Hello
You want to retrieve whole days of the month last query... So here's...
SELECT
TO_DATE(LEVEL||'-'||TO_CHAR(ADD_MONTHS(SYSDATE,-1),'MON-YY'),'DD-MON-YY') COMP_DATE,
TO_CHAR(TO_DATE(LEVEL||'-'||TO_CHAR(ADD_MONTHS(SYSDATE,-1),'MON-YY'),'DD-MON-YY'),'DD') ONLY_DD,
TO_CHAR(TO_DATE(LEVEL||'-'||TO_CHAR(ADD_MONTHS(SYSDATE,-1),'MON-YY'),'DD-MON-YY'),'MM') ONLY_MM,
TO_CHAR(TO_DATE(LEVEL||'-'||TO_CHAR(ADD_MONTHS(SYSDATE,-1),'MON-YY'),'DD-MON-YY'),'YY') ONLY_YY
FROM DUAL
CONNECT BY LEVEL <= TO_NUMBER(TO_CHAR(LAST_DAY(ADD_MONTHS(SYSDATE,-1)),'DD'))
I'm not at the machine database so not tested.
But one thing do not forget that this forum only for reports, it is a separate SQL and pl/sql instance.
Function to retrieve all the days of the previous month.
-Clément
Published by: Graham on April 22, 2010 22:53
Spelling error
Tags: Oracle Development
Similar Questions
-
Is there an automatic procedure to retrieve all the drivers on the Satellite U200?
I have re-installed XP on my Satellite U200 and lost all drivers and settings. Is there an automatic procedure to retrieve all the? I'm a bit mazed by 52 varieties of the drivers available on the support web site.
Thank you.
Alexey.
You are going to use the Toshiba Recovery CD or will allow you to install all the drivers manually.
I guess the recovery with XP CD is not available for this laptop and therefore only the manually installation is possible -
How can I retrieve all the values in a single query in the oracle XML
Hi all
I have xml format below, how do I retrieve all the values in a single query.
< files >
< job > MANAGER < / job >
< details >
< ename > JONES < / ename >
< sal > 2975 < / sal >
< ename > BLAKE < / ename >
< sal > 2850 < / sal >
< ename > CLARK < / ename >
< sal > 2450 < / sal >
< / details >
< / documents >
Thank you
I prefer desgin a little more sophisticated xml and wrap the details in a separate label.
Then you could something like that
1 with testdata until)
2. Select xmltype)
3'
4MANAGER
5
6
7JONES
82975
9
10
11BLAKE
122850
13
14
15CLARK
162450
17
18
19
20 ') in the form x
21 double
22)
23 select
24 j.job
25, d.ename
26, d.sal
27 of testdata
28 join
29 xmltable ("Scriptures" in passing testdata.x)
30 columns
31 job varchar2 (30) path "job."
32, details xmltype path «details»
(33) j
34 (1 = 1)
left outer join 35
36 xmltable (' details/emp' in passing j.details)
37 columns
path of varchar2 (30) 38 'ename' ename
39, path of varchar2 (30) sal "sal".
(40) d
41 * (1 = 1)
>/JOB ENAME SAL
------------------------------ ------------------------------ ----------
JONES MANAGER 2975
BLAKE MANAGER 2850
MANAGER CLARK 2450 -
How to get sales last day of the previous month
HELO guys
I have a question how do I get sales date last day of the previous month where my fact table is level. in fact I tried using Ago but it seems not working. for example, if I chose December 29, 2014 so if I used the function there are then the result will display data on November 29, 2014 (not the last day of November 2014).
Please guys if you have any solution and I really advise thanks to you.
Not exactly under what circumstances specific as you try to reach this goal, but suppose you have a few guest dashboard where you select a day and you have a report with a measure where you want to show the sales of the last day of the previous month based on the selected date in the dash prompt.
If you change the formula of this measure to something like:
FILTER (with the HELP of 'Sales' (DATE = TIMESTAMPADD (SQL_TSI_DAY-1, TIMESTAMPADD (SQL_TSI_DAY, DAYOFMONTH(@{PV_DATE_SELECTED}) * (-1) + 1, @{PV_DATE_SELECTED}))))
-
How to get the last business day of the previous month?
Hi all
We need the user as below,
If the user select 18 June 2015 ' quick dashboard as the input value, and then they want to see last month last day of work (business date: 29-may-2015) amount in report, if you have an idea please share with us.thanks
Note:
use under request we can able to get the last day of the previous month, we want to for the last business day of the last month, based on the date of entry of the user?
TIMESTAMPADD (SQL_TSI_DAY,-(1), TIMESTAMPADD (SQL_TSI_DAY, DAYOFMONTH ("DIM_TIME". ("" DataDate ") *-(1) + 1,"DIM_TIME ". (("" DataDate "))
Thank you
Deva
Try this,
case when Dayofweek (timestampadd (sql_tsi_day, Dayofmonth(Date '2015-06-15') *-1, Date ' 2015-06-15')) = 1 then timestampadd (sql_tsi_day, (Dayofmonth(Date '2015-06-15') *-1)-2, Date '' 2015-06-15) when Dayofweek (timestampadd (sql_tsi_day, Dayofmonth(Date '2015-06-15') *-1, Date ' 2015-06-15')) = 7 then timestampadd (sql_tsi_day, Dayofmonth(Date '2015-06-15') *-1-1, Date '' 2015-06-15) another timestampadd (sql_tsi_day, Dayofmonth(Date '2015-06-15') *-1, Date ' 2015-06-15') end
As Ftsiot said in this post, it will work only to exclude the sat and Sun. Another one if you want to exclude regional holiday, you may need a calendar in DB table.
Thank you
AJ
-
Difficulty accessing data by using the function of Ago - the end of the previous month
Hey,.
Recently, I met a problem that I can't fix on my own.
I need to compare my portfolio to the current date / specified with the portfolio for intelligence and for the end of the previous month (the last day of the previous month).
It looks like this :
My fact table consists of the list of contracts of loan that is updated daily. The data for the new day are added to the table, which actually resemble a large sandwich of various portfolios.
To recover the data for the current/specified date and intelligence is not a problem. Current date - the date is read (can 10.08.2014), the day before - I use the Ago function (e.g., 09.08.2014).
The real problem is getting the data for the last day of the month previous (e.g. 31.07.2014), since I can't put a specific to the function of Ago offset (10 days in our example), as the number of days from the end of the previous month is constantly - changing is a daily report.
The best solution would be setting the offset function there is a dynamic value, which would change according to the user selects the date of the report. Can be based on the number of days in the month. BI strictly prohibits using anything that is not an integer in the offset value, so this isn't an option.
I tried a work around using formulas in columns, like: FILTER ('facts of agreements'. "" Outstanding "USING ("Posting Date". "" Id of the day ' = TIMESTAMPADD (SQL_TSI_DAY, TIMESTAMPADD (1), (SQL_TSI_DAY, 'Date of Report'.) "Number of the day in the month" *-(1) + 1, DATE ' @{report_date}'))). "
It did not work, since the data I receive are dated the last day of the previous month and date, which is applied to get the data for the current date filter / specified, it cuts.
Tried to create another time the hierarchy, with the ends of period (week, month, quarter, year) and use it as a level at the Ago. He does work in part, offset the end of 1 month, but I can't bind the data, I get to the date of the report, as the Ago function returns random dates.
I tried to search if people have had the same problems and it seems I'm the only one. I'm really desperate at this point, not even sure it's possible to get the result I need everything.
So, please advise!
Aurore
Finally got sorted! Hoorey!
Here's how it's done:
I created a presentation variable 'report_date' for the user to choose the date of the desired report. That this formula has added to the column:
FILTER ('facts of agreements'. "" Outstanding "USING ("facts of agreements". (("" Days late max "> 30))-there is (FILTER ('facts of agreements'. "" Outstanding "USING ("facts of agreements". ((("" Days late max "> 30)), TIMESTAMPDIFF (SQL_TSI_DAY, TIMESTAMPADD (SQL_TSI_DAY, DAYOFMONTH (DATE ' @{report_date}') *-1, DATE ' @{report_date}" "), DATE ' @{report_date}'))
Basically, this formula is used to calculate the difference between the current amount of the portfolio and the amount of portfolio for the last day of the last month (or at the end of last month), where only loans with number of days late over 30 are included.
In the service there, I used a TIMESTAMPDIFF as a compensation formula to calculate the difference in days between the date of the report and the end of last month. Now no matter what date the user chooses it will give the correct difference in days.
Really easy, but it took me a little time to get there.
Hope this helps someone
-
retrieve December as the previous month in 2013
All,
I used this code to retrieve the previous and upcoming months last year that worked very well...
If the date was for example September 7, then a list of the previous months must be shown, and a list of the next months including the current month.
select to_char(to_date(level,'mm'),'FMMonth') month from dual connect by level < to_number(to_char(sysdate,'mm')) MONTH --------- January February March April May June July August
Now we are in January 2013.select to_char(add_months(sysdate,level - 1),'FMMonth') month from dual connect by to_number(to_char(add_months(sysdate,level - 1),'mm')) != 1 MONTH --------- September October November December
When I run the code for the previous months, there is no line. It is right that there is no previous month again in 2013.
I would like to extend the code to display December 2012 as the previous month at the beginning of the year.
How can I achieve this?
Thank you
DianaHello
Try this:
select to_char(trunc(add_months(sysdate, -level) ,'month'),'FMMonth-yyyy') previous_months from dual connect by level <= case when to_number(to_char(sysdate,'mm')) = 1 then 12 else to_number(to_char(sysdate,'mm'))-1 end order by add_months(sysdate, - level)
If wew replace sysdate with date ' 2013-01-08' then it results in:
select to_char(trunc(add_months(date '2013-01-08', -level) ,'month'),'FMMonth-yyyy') previous_months from dual connect by level <= case when to_number(to_char(date '2013-01-08','mm')) = 1 then 12 else to_number(to_char(date '2013-01-08','mm'))-1 end order by add_months(date '2013-01-08', - level) ; PREVIOUS_MONTHS --------------- January-2012 February-2012 March-2012 April-2012 May-2012 June-2012 July-2012 August-2012 September-2012 October-2012 November-2012 December-2012 12 rows selected
If we replace sysdate with date ' 2013 - 02 - 08, then we get:
select to_char(trunc(add_months(date '2013-02-08', -level) ,'month'),'FMMonth-yyyy') previous_months from dual connect by level <= case when to_number(to_char(date '2013-02-08','mm')) = 1 then 12 else to_number(to_char(date '2013-02-08','mm'))-1 end order by add_months(date '2013-02-08', - level) ; PREVIOUS_MONTHS --------------- January-2013
Same thing for 2013 - 05-08 "
select to_char(trunc(add_months(date '2013-05-08', -level) ,'month'),'FMMonth-yyyy') previous_months from dual connect by level <= case when to_number(to_char(date '2013-05-08','mm')) = 1 then 12 else to_number(to_char(date '2013-05-08','mm'))-1 end order by add_months(date '2013-05-08', - level) ; PREVIOUS_MONTHS --------------- January-2013 February-2013 March-2013 April-2013
Kind regards
Peter
-
DAY MONTH FOR THE previous month
Hello
I invited where I have dates like below
31/03/2012
30/04/2012
When I clcik 30/04/2012, I need previous months the other day, then the result should be 31
When I give it as this TIMESTAMPADD (SQL_TSI_DAY,-30, DATE ' @{pvdate} "")... I get previous full day 31/03/2012
When I give it as this DAYOFMONTH (DATE ' @{pvdate} "")... I get months current 30 day
How to get the previous month of day?If you use guests then SQL result or in the SQL report to filter or fx on column
-
Display the previous month data based on the chosen date
Hi all
I need the report of this requirement:
The user selects an "Invoice Date" with guests, then it should be able to view the data of the previous month until the date (i.e.; If he chooses on 6 July in the hour that I need to view the data of June 6). How can I achieve this?
Thank you
JeromeHi timestampadd function used in your filter.
At the command prompt have a variable presentation as invoice_date and your report using the filter as below,
"The date of the invoice" > = timestampadd(sql_tsi_day,-30,'@{invoice_date}')
and "Date of the invoice.<=>=>Published by: kart on July 6, 2010 11:24
-
Compare the amount of the previous month based on the account number
Hi team,
In my table of the source, amount aggregated by month for a given account there
Now, I need to add a column more in this area, with logic below. There will be more than 1000 accounts available. For each account I need to achieve this.ACCOUNT_NUMBER YEAR MONTH AMOUNT --------------- ------- ------ ----------- 123456789 2012 01 450.00 123456789 2012 02 -234.00 123456789 2012 03 0.00 123456789 2012 04 890.00 123456789 2012 05 78.00 123456789 2012 06 44444.00 123456789 2012 07 450.00 123456789 2012 08 450.00 123456789 2012 09 450.00 123456789 2012 10 120.67 123456789 2012 11 176.88 123456789 2012 12 450.00 123456789 2013 01 340.00
CASE WHEN MONTH_AMOUNT = 0 THE CASE OTHERWISE 1-0 WHEN PREVIOUS_MONTH_AMOUNT = 0 THEN 0 1 OTHER)
On this basis, the objective should be
can someone help me how to compare the value of the previous month. All columns have the data varchar, except for the quantity type.ACCOUNT_NUMBER YEAR MONTH AMOUNT FLAG --------------- ------- ------ ----------- ------------- 123456789 2012 01 450.00 1 123456789 2012 02 -234.00 1 123456789 2012 03 0.00 -1 123456789 2012 04 890.00 1 123456789 2012 05 78.00 1 123456789 2012 06 44444.00 1 123456789 2012 07 450.00 1 123456789 2012 08 450.00 1 123456789 2012 09 450.00 1 123456789 2012 10 0.00 1 123456789 2012 11 0.00 0 123456789 2012 12 450.00 1 123456789 2013 01 340.00 1
Hello
I have not tried. But this desire.
SELECT ACCOUNT_NUMBER, YEAR, MONTH, AMOUNT, CASE WHEN AMOUNT = 0 THE 0 ELSE 1 - CASE WHEN LAG(AMOUNT, 1, 0) OVER (PARTITION BY ACCOUNT_NUMBER ORDER BY YEAR, MONTH) = 0 THEN 0 ELSE 1) AS FLAG FROM SOURCE_TABLE;
See you soon
DidierPublished by: Didier vishwakarma on 6 March 2013 12:36
-
Cannot restore to a restore point from the previous month.
original title: my system restore won't let me restore to the previous month, the radio button works, but the habit of restoration
my windows XP THAT behaves strangely and I tried to use the system restore which has worked well in the past, but now he's depressed the option button but nothing happens
Roy
Hello
1. are you able to restore the computer to other points of restoration?
2. you receive an error message when you try to perform the system restore?
If you are not able to restore the computer to any pint of previous restoration then you can check the steps in the link below to fix the problem.
Steps of troubleshooting for problems when you try to use the System Restore tool in Windows XP
-
Download of the previous months
I signed up for Stock a few months ago. Unfortunately, I had a few personal problems because of which I had to take a break. I came back to the content of the license and realized that my previous allowances do not. I was under the impression that 10 permit licenses for June and July meant that, in the month of August, I would have 30 license. However, I don't see 10.
Is it possible to download the licenses of the previous month I have not used?
As long as your subscription has been paid, you should have these credits. Otherwise, open a session completely exhausted, close your browser, clear the cache of your browser and try again.
-
How to get the previous month and year accordingly
Hi friends,
I wanted to select the month as a number like 4 and the new year 2011
but I want to choose the previous month from sysdate
as if the sysdate is June 10, 2011
It should give me 5 months and
in the year, it should give as 2011
If the sysdate is January 1, 2012
the month should be like 12 and year should be in 2011
Thank youHello
776317 wrote:
Thank you very much I just the 0 being the prefix... can you pls how to avoid that too well plsTO_CHAR ( ADD_MONTHS (SYSDATE, -1) , 'FMmm yyyy' )
For more information on the FM, wee manual SQL language modifier works:
http://download.Oracle.com/docs/CD/B28359_01/server.111/b28286/sql_elements004.htm#sthref456 -
Extract the first and the last Date of the previous month
This seems to be a delicate but again it is perhaps easy for some of you people.
Here is how I find the previous month
Any ideas on how to get the first and last date of the previous month?
Thanks in advance.Hello!
SQL> SQL> select last_day(add_months(sysdate,-1)) from dual; LAST_DAY -------- 28.02.10 SQL> select trunc(add_months(sysdate,-1),'MM') from dual TRUNC(AD -------- 01.02.10 SQL>
T
-
extract the previous month of sysdate
The following SQL statement returns zero output.
I want to request to return to the previous month on any date given (sysdate).SELECT DISTINCT EXTRACT(MONTH FROM SYSDATE) - 1 PRVMNTH FROM DUAL
Help, please.
YogeshSQL> select extract (month from add_months (sysdate, -1)) 2 from dual 3 / EXTRACT(MONTHFROMADD_MONTHS(SYSDATE,-1)) ---------------------------------------- 12
Why the separate?
Maybe you are looking for
-
I have a my I plugged Mac when I turn again the fan is now blowing air all the time
I un plugged my I Mac when turns again the fan is now blowing air without stop
-
How to choose another HD than the default (C:?) for the recording of the mail
The other day I went to my old XP Pc to my 7 Pc W and started using Thunderbird w ' XP comes to expiration and Outlook Express. I used to store mail in a second HD to save space on the system - / C: drive programI would do the same thing using Thunde
-
July 13, 2010: My Firefox toolbar has suddenly disappeared, except for the back arrows on the left side. I tried Firefox stop and start several times, but nothing has changed. All toolbars are selected in the view menu... but nothing is visible!
-
Pavilion P6520F: downgrade windows 10 for windows 7 hp pavilion p6520f
As a upgrade middle-of-the-night involuntary Windows 10 occurred, Can not stop random reboots every 20 to 45 minutes. I give up. I know that there is an opportunity (allegedly) to downgrade to Windows 7 in the first 30 days, but I wanted to make su
-
Equium L40 problems using the recovery disk
Hello I wonder if anyone can help me? I want to restore my computer but when I put the recovery disk in I select the cd/dvd rom drive by pressing f12 at startup.I also maintained pressed C when I lit. I select the disc I want to start the computer, i