last working day of each week
Hello worldCould someone suggest how to configure Oracle 11g Scheduler so that it would start the last working day of each week? The last business day of the week is not always Friday; exceptional days are configured in separate planners, who are included or excluded in clause repeat_interval, (for example).
The last business day of each month, works well, like this:
BEGIN
DBMS_SCHEDULER. () CREATE_SCHEDULE
schedule_name = > "LAST_SETT_DAY_OF_MONTH"
repeat_interval = > ' FREQ = MONTHLY; BYHOUR = 18; BYMINUTE = 30; BYDAY IS MON, MAR, SEA, GAME, FRI.; BYSETPOS =-1; EXCLUDE = HOLIDAY; INCLUDE = EXCEPTIONAL_WORKING_DAYS; ") ;
END;
But I want to run a similar logic for weeks.
Thanks in advance
OK, now I understand your request.
I think it might be possible for PL/SQL function.
Create the table suite where you put your nonworking days and the additional working days. To create the PL/SQL function and use
CREATE TABLE day_list(
DAY DATE NOT NULL,
TYPE NUMBER(1) NOT NULL,
CONSTRAINT pk_day_list PRIMARY KEY(DAY),
CONSTRAINT ch_day_list_type CHECK(TYPE IN (1,2)));
-- type 1-nonworking day,2-extra working day
CREATE OR REPLACE FUNCTION last_working_day(p_date IN DATE) RETURN DATE AS
v_retval DATE := TRUNC(p_date);
v_aux DATE;
BEGIN
IF v_retval IS NOT NULL
THEN
-- get next friday
dbms_scheduler.evaluate_calendar_string(calendar_string => 'FREQ=DAILY; BYDAY=FRI',start_date => v_retval,return_date_after => v_retval,next_run_date => v_retval);
-- check if SUNDAY or SATURDAY is extra working day
SELECT MAX(DAY)
INTO v_aux
FROM day_list
WHERE TYPE=2
AND DAY BETWEEN v_retval+1 AND v_retval+2;
IF v_aux IS NOT NULL
THEN
v_retval := v_aux;
ELSE
-- find last working day from monday to friday
WITH v_1 AS (SELECT v_retval - LEVEL +1 AS DAY
FROM dual
CONNECT BY LEVEL <=5)
SELECT MAX(DAY)
INTO v_aux
FROM (SELECT v_1.day, CASE WHEN t.type=1 THEN 0 ELSE 1 END is_working_day
FROM v_1
LEFT JOIN day_list t ON v_1.day=t.day AND t.type=1
)
WHERE is_working_day=1;
-- there is a working day
IF v_aux IS NOT NULL
THEN
v_retval := v_aux;
ELSE
-- go to next week
v_retval := last_working_day(v_retval);
END IF;
END IF;
END IF;
RETURN v_retval;
END;
/
Tags: Database
Similar Questions
-
I'm looking for the 1st working day of the week.
Hello
I'm looking for the 1st working day of the week except Saturday, Sunday and holidays. I have vacation, the name of the table that contains the columns HolidayDate and HolidayDescription.
Ex:
01/10/2011 is monday (i.e) 1st company day.check if it is in the host table, then return the result as 01/11/2011 other returns the output as a 11-1-2011(which is the first business day of this week).
Can someone tell me the query to solve?Hello
If dt is any DATE, it is the first day of work in the same week as dt:
WITH all_week AS ( SELECT TRUNC (dt, 'IW') + LEVEL - 1 AS a_dt FROM dual CONNECT BY LEVEL <= 5 ) SELECT MIN (a_dt) AS first_work_dt FROM all_week WHERE a_dt NOT IN ( SELECT holiday_dt FROM holiday ) ;
This assumes that you have never 5 consecutive days. (Where I work, holidays are always at least a week apart, so that's fine.)
If you have a week's holiday, increase the number of 'magical' in the CONNECT BY clause.It also means that holiday.holiday_dt = TRUNC (holiday.holiday.dt).
-
How to view the 3rd working day of each month.
Hello
could someone help me with a proc to display the 3 day working rd of each month?
By day, I mean working Mon - Fri.
Thank you.Hello
Sorry, I initially responded to the question "what is the * first * work of the month ', which is a little easier.
Here's a way you can code in SQL:
ALTER SESSION SET NLS_DATE_FORMAT = 'DD-Mon-YYYY Dy'; WITH got_dates AS ( SELECT TRUNC ( ADD_MONTHS (SYSDATE, LEVEL) , 'MONTH' ) AS a_date FROM dual CONNECT BY LEVEL <= 12 ) -- The part above just generates some sample dates -- The part below is the actual query: -- SELECT a_date , CASE TO_CHAR ( a_date + 2 , 'fmDay' , 'NLS_DATE_LANGUAGE=ENGLISH' -- If needed ) WHEN 'Monday' THEN 4 WHEN 'Tuesday' THEN 3 WHEN 'Saturday' THEN 4 WHEN 'Sunday' THEN 4 ELSE 2 END + a_date AS third_workday FROM got_dates ORDER BY a_date ;
Output:
A_DATE THIRD_WORKDAY --------------- --------------- 01-Nov-2012 Thu 05-Nov-2012 Mon 01-Dec-2012 Sat 05-Dec-2012 Wed 01-Jan-2013 Tue 03-Jan-2013 Thu 01-Feb-2013 Fri 05-Feb-2013 Tue 01-Mar-2013 Fri 05-Mar-2013 Tue 01-Apr-2013 Mon 03-Apr-2013 Wed 01-May-2013 Wed 03-May-2013 Fri 01-Jun-2013 Sat 05-Jun-2013 Wed 01-Jul-2013 Mon 03-Jul-2013 Wed 01-Aug-2013 Thu 05-Aug-2013 Mon 01-Sep-2013 Sun 04-Sep-2013 Wed 01-Oct-2013 Tue 03-Oct-2013 Thu
Published by: Frank Kulash, October 4, 2012 17:56
-
Work day of the week of the date of
Hi guys, is a bit common code that allows you to work on the day of the week for a given date? IM pretty new to this and I don't know how to write it and thought since it's probably quite commonly need I may be able to get help here. Thank you.Day of the week in letters
Select to_char (sysdate, 'day') of double;Day of week in numbers
Select double to_char(sysdate,'D');Day of the month in figures
Select to_char (sysdate, 'DD') of double; -
PL/SQL function to calculate the non-working days
Hello
I have the following pl/sql function which generates a number of days between two selected dates (i.e. excluding weekends). However, I also need to exclude specific holidays - day of Christmas etc. These holiday dates are stored in a table in our database (11 GR 2) called "HOLIDAY".
How can I integrate the holidays which is held in the table of holidays in the following query to exclude these dates as well? I know how to write a separate funtion pl/sql for a number of days between two dates using SELECT... BUT I can't work out how to bring together them in a single query.
Could someone show me how with the pl/sql / dates below please?
Example of HOLIDAY table below.
Thank you!
TP
create or replace function WORKING_DAYS (pi_start_date in date, pi_end_date in date) return integer is v_start_date date :=pi_start_date; v_end_date date:=pi_end_date; v_count integer:=0; begin while v_start_date <= v_end_date loop if to_char(v_start_date,'D') not in ('6','7') then v_count := v_count+1; end if; v_start_date:=v_start_date+1; end loop; return v_count; end;
(select '10-Apr-2013' as NWD from dual union all select '06-May-2013' from dual union all select '27-May-2013' from dual union all select '26-Aug-2013' from dual union all select '26-Dec-2013' from dual union all select '25-Dec-2013' from dual union all select '01-Jan-2014' from dual union all select '18-Apr-2014' from dual union all select '21-Apr-2014' from dual union all select '05-May-2014' from dual union all select '26-May-2014' from dual union all select '25-Aug-2014' from dual union all select '25-Dec-2014' from dual union all select '26-Dec-2014' from dual) HOLIDAYS
Hello
the link is on MOSC, not OTN... Here's a copy:
This function calculates the number of days between two dates, ignoring weekends and holidays (if requested and if the holidays are stored in a table)
I give an example of table 'public_holiday' with sample data, but users must ensure that their table contains the relevant data (all holidays within the maximum range of use of the service)
CREATE TABLE public_holiday (calendar_day, DATE, text VARCHAR2 (30));
FUNCTION to CREATE or REPLACE nb_days (p_date_from IN DATE
p_date_to DATE by DEFAULT TRUNC (sysdate)
, p_public_holidays in CHAR DEFAULT 'Y '.
) RETURN NUMBER
DEFINE AUTHID
AS
/*********************************************************************/
/ * Author: Bruno Vroman * /.
/ * Created: 23-AUG-2012 * /.
/ * Last updated: 23-AUG-2012 * /.
/ * Object: to calculate the number of days between 2 dates, to the exclusion of * /.
/ * Saturday and Sunday, but also "holidays" If the * /.
/ * argument 'p_public_holidays' = 'Y ' * /.
/ * Support: p_date_from<= p_date_to ="">=>
/ * component ' hour min dry "ignored (just counting days) * /.
/* First step: */
/ * the calendar days between 2 days * /.
/ Remove 2 days for each "week" and 0 or 1 extra day * /.
/ * function to a condition "complex" mix day of first week * /.
/ * and the number of days when full remaining weeks are removed * /.
/ * (set up once for all, for example if there is 3 days and the * /)
(/ * first day is a Thursday, there is 1 "Sat/Sun" to subtract) * /.
/ * Second step: If 'p_public_holidays' = 'Y': other * /.
/ * days, do not count holidays. */
/ Holiday everyday are defined in a table "public_holiday" * /.
/ * Note: there may be holidays defined on Saturday/Sunday. */
/*********************************************************************/
l_result NUMBER;
l_from DATE;
l_to DATE;
l_case tank (4);
BEGIN
l_from: = TRUNC (p_date_from);
l_to: = TRUNC (p_date_to);
l_case: = TO_CHAR (l_from, 'Dy', 'NLS_DATE_LANGUAGE = English').
To_char (MOD (l_to - l_from + 1, 7));
l_result: = l_to - l_from + 1
-TRUNC ((l_to-l_from + 1) / 7) * 2
-CASE
WHEN l_case IN ('Mon6', 'Tue5', 'Wed4', 'Thu3', 'Fri2'
, "Sat1", "Sun1", "Sun2', 'Sun3", "Sun4".
, "Sun5', 'Sun6.
)
THEN 1
WHEN l_case IN ('Tue6', 'Wed5', 'Wed6', 'Thu4', "Thu5"
, 'Thu6', 'Fri3', 'Fri4', 'Fri5', 'Fri6 '.
, "Sat2", "Sat3', 'Sat4', 'Sat5", "Sat6.
)
THEN 2
0 OTHERWISE
END
;
IF SUPERIOR (p_public_holidays) = "Y".
THEN
SELECT l_result - COUNT (*)
IN l_result
OF public_holiday p
WHERE p.calendar_day > = l_from
AND p.calendar_day<=>=>
AND SUBSTR (TO_CHAR (p.calendar_day
, "Dy".
'NLS_DATE_LANGUAGE = English'
)
, 1, 1 ) != 'S'
;
END IF;
RETURN l_result;
EXCEPTION
WHILE OTHERS
THEN
DBMS_OUTPUT. Put_line (' CTF nb_days (' |))
To_char (p_date_from, "MON-DD-YYYY"). ', ' ||
To_char (p_date_to, "MON-DD-YYYY"). ', ' ||
p_public_holidays | ' ) : ' || SQLERRM
);
LIFT;
END nb_days;
/
REM
REM example:
REM A) fill out the 'public_holidays '.
REM
TRUNCATE TABLE public_holiday;
INSERT INTO public_holiday VALUES (DATE ' 2012-01-01', ' new year (a Sunday)');
INSERT INTO public_holiday VALUES (DATE '' 2012-01-03, "for example");
REM (insert other days...)
COMMIT;
Call the function for some pairs of dates of REM B)
REM nb1: remove only Sat/Sun
REM nb2: also remove holidays
REM
ALTER SESSION SET nls_date_format ='Dy DD-MON-YY';
WITH some_dates AS
(SELECT DATE ' 2011-12-29'd dual FROM
UNION ALL SELECT DATE ' 2012-01-08' FROM dual
UNION ALL SELECT DATE ' 2012-01-10' FROM dual
)
SELECT d1.d 'FROM '.
, d2.d ' to THE '.
, nb_days (d1.d, d2.d, ' don't) nb1
, nb_days (d1.d, d2.d, 'Y') nb2
OF some_dates d1
some_dates d2
WHERE d1.d<=>=>
ORDER BY nb1, nb2, d1.d
;
GO TO NB1 NB2
------------- ------------- ---- ----
Monday, January 8, 12 Monday, January 8, 12 0 0
Friday, December 29, 11 Friday, December 29, 11 1 1
Wednesday, January 10, 12 Wednesday, January 10, 12 1 1
Monday, January 8, 12 Wednesday, January 10, 12 2 2
Friday, December 29, 11 Monday, January 8, 12 7 6
Friday, December 29, 11 Wednesday, January 10, 12 9 8
Hope that this could be useful, but note that this code has not been completely tested, so check and test before you trust it (in the case of any questions, please post a comment)
Bruno Vroman.
Best regards
Bruno
-
* Original title: screen flickers
These last days on each screen by clicking on sparkles and top rollers at the bottom makes it difficult to work. What could be the reason? Windows 7 Professional operating systems.
I have since uninstalled Adobe Flash as Java and I find twinkle and has stopped rolling top screen downstairs. In case the problem recurs, I'll follow the advice given by you. Thanks for your quick response.
-
use to insert the last day of each month
Hi, I wrote this code but it did not insert the 20 December and it is January 1, and next time running is 31 January... I would like to work to make this insert every last day of each month...
I don't know if it's because I assigned the date 31-10... In November it's just but December has not...begin sys.dbms_job.submit(job => :job, what => 'INSERT INTO hisrtu SELECT rtunum, linked, dbchkd, chaqty, dbvald, ctrltr, meaadj, qtyrtu, month, year, entity, rtunam FROM qtyrtu;', next_date => to_date('31-10-2010 01:00:03', 'dd-mm-yyyy hh24:mi:ss'), interval => 'SYSDATE +30'); commit; end; /
Best regards, hope you can help me.
I use oracle 9iHello
If you want the job to run at 02:00 the last day of the next month, then the desired argument is:
interval => 'ADD_MONTHS (TRUNC (SYSDATE, ''MONTH''), 2) - (22 / 24)'
In other words, if she finishes running at 02:30 on 31 January, then
TRUNC (SYSDATE, 'MONTH') will be at 00:00:00 January 1
ADD_MONTHS (TRUNC (SYSDATE, 'MONTH'), 1) will be March 1st at 00:00:00
ADD_MONTHS (TRUNC (SYSDATE, 'MONTH'), - 1) (22 / 24) will be 22 hours earlier, i.e. 02:00 on the last day of February.logandro wrote:
I don't know if it's because I assigned the date 31-10... In November it's just but December has not...Do you mean this line?
next_date-online to_date (October 31, 2010 01:00:03 ',' dd-mm-yyyy hh24:mi:ss'),
I don't think that's a problem. The next_date specifies only when it work baptisms. I guess he ran on October 31; you said it was running well on 30 November, 30 days after that. Something has to happen after November 30.
Note that the interval argument is relative when the task completes. If a task takes 30 minutes to run, then
interval => 'SYSDATE +30'
means that, if it turns to
01:00:03 October 31, then it will run again about
01:30:03 November 30, around
02:00:03 on December 30.
02:30:03 January 29 and so on. If your business does that for a few seconds, it won't matter much.If you decide to use LAST_DAY, don't forget not that the hours-minutes-seconds referring LAST_DAY are the same as those of his argument.
-
Download all dates for each day of a week
I need a VI that gives me the dates of the week. I use a calendar month to look at a database and fill two different graphs with the database values. A chart looks at the values of the specific day, I chose in the calendar, but the other graph looks like all the days of the week. To create this SQL query, I need to have all the dates this week.
I could build a function if I knew that the first and last date of the week. Anyone know an easy way to do this?
Use the Second to primitive time to convert your day to a cluster of time. One of the elements of the cluster is the day of the week that should allow you to easily find the end of the week (you can add 2 days and convert back or add 2 with the unit of the timestamp of origin).
-
It seems to me that this is not possible, but is there a way I can put a recurring appointment for a certain day of the week of each month in the calendar on the Surface RT? For example, a meeting Tuesday on two or one excursion each fourth Sunday? I know that this is possible in Outlook on a PC and I would like to do it on the Surface RT as well. Most of my recurring appointments are of this type. When I recur every month on the Surface, it just sets it for the same date (for example the 12th of each month) instead of the second Tuesday. Thank you!
Hi Lisa,
You were correct when you say that 'it seems to me that's not possible. ' The recurring appointment for some day of the week each month in the calendar on Surface RT cannot be done by date and not day.
Good day!
-
When you try to run the company, I received this error for the last two days. I have tried using another browser and ended in the same results.
Please try again later
We are working to improve your experience of the Enterprise Dashboard.
Hello
Your proof of cloud creative's 'VIP' instead of the company, so you would not normally manage your CC on the Enterprise Dashboard, but you had some Digital Marketing rights so that's why you have a dashboard.
I am informed that currently some adjustments are made to your dashboard for Digital Marketing and that it should end soon.
In the meantime your creative team of cloud management should be available through creative.adobe.com
-
I was working on a scenario week last on my PC at home. Yesterday, I tried to loggin to my work computer, and I was asked to reset my password before continuing. I did it according to the instructions, but when I was able to access the history, I found that my script is not there. How can I get it back?
Looks like you worked in the desktop application in the history of offline through your PC at home.
You can check by logging into the desktop app from your home PC and checking if the word "offline" appears after the name of your account at the top right of the story.
If that's true then please switch to online mode.
-
The product I bought doesn't work! I need help and I was stuck in your 'contact us loop' for the last few days and I'm frustrated. How can I contact you for help!
Probably the best place to start is the right forum for your product. This is the forum for Distiller Server, a product used by corporations long dead, and probably not what you have. If you can't find the right forum, please let us know the FULL name of what you paid for (Please check your invoice, as Adobe have a lot of similar products), and we may be able to direct you. Good luck!
-
Hi friends,
I have the below query that returns me the data as below:
Select 'Label', to_number (to_char (to_date(start_date,'yyyy-mm-dd'), 'IW')) - to_number (to_char (add_months (sysdate,-6), 'IW')) + 1 as a weekly sum, (col1) val yyy_view
where to_date(start_dt,'yyyy-mm-dd') between trunc (add_months(sysdate,-6)) and trunc (sysdate)
Group of to_char (to_date(start_date,'yyyy-mm-dd'), 'IW')
order of to_char (to_date(start_date,'yyyy-mm-dd'), 'IW')
Label weekly val
1 20 data
2 24 data
3 20 data
4 28 data
5 20 data
6 24 data
and so on...
Now the requirement is to get the last date of the week for each week as below
Label weekly val
given 2011-08-30 20
given 2011-08-23 24
given 2011-08-16 20
given 28 2011-08-09
given 2011-08-02 20
the weekly column should have the date of the last week. In the example above Wednesday is supposed to be the last date of the week.
Kind regards
PradeepMissed the part "Wednesday is considered date of last week. The week is Thursday to Wednesday. If so:
select 'Label', trunc(min(start_dt)) as day2, sum(col1 ) val from yyy_view where start_dt between trunc(add_months(sysdate,-6)) and trunc(sysdate) group by trunc(start_date - 3,'IW') order by trunc(start_date - 3,'IW') /
SY.
-
How to get the last day of the week?
HII
I can get the week number of calendar for a given date using
SELECT to_char (to_date('04/04/2011','MM/DD/YYYY'), 'WW') FROM dual
can any body tell me, how to get the last day of the week?
and the answer should be: 04/08/2011(8th april)
Thank you
San
Published by: sandeep9 on April 4, 2011 03:50Perhaps this...
SQL> select trunc(sysdate,'WW')+6 from dual; TRUNC(SYSDATE,'WW')+ -------------------- 08-APR-2011 00:00:00 SQL>
-
First day/last day of each month
Hello
y at - it sql/script to get the first day/last day of each month.new to bi do not know the syntax
If a point on the link to get these things will be highly appreciatedHello
I suggest that you go through the following link(1) http://oracle.ittoolbox.com/groups/technical-functional/oracle-bi-l/obiee-date-comparison-1726677#M1729534
Toget first/last day of the month
(2) http://www.obinotes.com/2010/02/tip-to-get-firstday-lastday.html
New to OBIEE---> http://obiee101.blogspot.com/2009/07/obiee-how-to-get-started.html
Thank you
Saichand.V
Maybe you are looking for
-
I changed my phone from my work network will still pay Apple?
Hello I just changed my phone at Virgin in EA network provider, I wore my phone number and now, everything seems ok, but when I tried to pay through my Apple Watch the card reader just didn't flinch when I tried it. That is likely to be just a proble
-
How to completely reset my iPad 2 to factory settings
How to completely reset my iPad 2 to factory settings? I just got a new iPad 2 Air and want to give my old my friend, but to clean completely first. Thanks for your help.
-
Is iPhoto 9.6.1 the latest version?
It was mentioned in the forum you can continue to use iPhoto after upgrading to El Capitan, "If you kept iPhoto to date." How will I know if iPhoto is up-to-date? There is no update available in the App store. I remember never be asked if I wanted to
-
Dell Dimension 2400 with XP.
-
I installed H & R Block 2010 Home Premium on windows vista. I lived a kind of attack via the web, on my machine. After fixation by restoring to a previous restore point, when I click on the application of H & R to launch I get this: No authorization