Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: DBMS_JOB scheduling

RE: DBMS_JOB scheduling

From: Jamadagni, Rajendra <Rajendra.Jamadagni_at_espn.com>
Date: Wed, 23 Jul 2003 09:26:08 -0400
Message-Id: <25998.339112@fatcity.com>


This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible.

------=_NextPartTM-000-1774fbea-cef8-443a-b02a-80285259ee4c Content-Type: multipart/alternative;

        boundary="----_=_NextPart_001_01C3511D.F9CCC707"

------_=_NextPart_001_01C3511D.F9CCC707
Content-Type: text/plain;

        charset="iso-8859-1"

Garry,

  1. have you tried select to_char(sysdate,'D') from dual ??

This is really nice, but my only gripe with dbms-job is that is isn't reliable ... it wasn't in 9ir1 on aix and we didn't even look at it in 9ir2. in 9ir1 dbms_job used to _forget_ to run jobs after some time and the workaround was like setting job_processes to a very large number.

nevertheless, I think what you have attempted is fantastic and worthy of adoption ...

Raj




Rajendra dot Jamadagni at nospamespn dot com All Views expressed in this email are strictly personal. QOTD: Any clod can have facts, having an opinion is an art !

-----Original Message-----
From: Garry Gillies [mailto:g.gillies_at_weir.co.uk] Sent: Wednesday, July 23, 2003 5:59 AM
To: Multiple recipients of list ORACLE-L Subject: DBMS_JOB scheduling

Any Interest?

The DBMS_JOB package is supplied by Oracle to allow the running of procedures at regular intervals. Unfortunately the INTERVAL parameter is limited to 128
characters, which prevents you from getting very complex (user defined functions [in the interval parameter] do not work well - according to Fuerstein in his book Oracle Built In Packages).

The situation is eased somewhat by the fact that the NEXT_DATE parameter can be supplied to the procedure as an in/out parameter - and the procedure can contain whatever code is necessary to calculate when next to run. This is all very well, but custom coding scheduling routines can quickly become tedious.
On the basis of "do it once and get it over with" I have written a function called NEXT_DATE which I have wrapped in a package called CRON.

There is a Unix program called cron which runs jobs on a regular basis. Although the scheduling data supplied to cron is simple and concise, complex schedules are easy to specify.

The NEXT_DATE function takes in a cron schedule string and returns the next date that conforms to the schedule - or you can supply a cron schedule and a date
and it will return the first date after the supplied date that conforms to the schedule. At the moment it is not very friendly on the error detection front. A VALUE_ERROR is returned if it deems the cron schedule to be invalid. You will also get a VALUE_ERROR if the next valid date is more than twenty seven years in the future. DBMS_OUTPUT is used to display error messages which will hopefully give you a clue.

This will be improved if I receive enough complaints ( and suggestions for improvements).

THE CRON SCHEDULE A cron schedule consists of five components, each separated from the next by a space.
The syntax is identical for all components. The components represent

         Minute in Hour
         Hour in day
         Day in month
         Month in year
         Day of Week - A bit of a bugger this one. 
         In Unix land the day numbering runs from 0-6 with 0 being Sunday.
In Oracle the day numbering depends on the setting of NLS_TERRITORY.
         I have chosen to go with ISO standard  8601:1998 which runs from
1-7 with 1 being Monday. This is so close to the Unix convention that I can interpret Unix cron schedules correctly.

         Curiously, Oracle do not provide a date format which supplies this number. The ISO week number is available with the format 'IW', but not the ISO day number. If you have a field of type date called dt, you can obtain the ISO day number with ( trunc(dt) - trunc(dt ,'IW') ) + 1 A component can consist of an asterisk * which represents all valid values or a number of elements separated by a comma (if only one element is supplied, forget the comma). An element can be a single number - valid for the component (32 in "Day in month" is invalid) or two numbers separated by a hyphen - which represents a range.

EXAMPLES Run every hour on the hour

     0 * * * *
Run twice every hour, on the hour and on the half hour

     0,30 * * * *
Run twice every hour, on the hour and on the half hour between 08:00 and 16:59

     0,30 8-16 * * *
Run twice every hour, on the hour and on the half hour between 08:00 and 16:59, Monday to Friday

    0,30 8-16 * * 1-5
Run at 11:12 every Friday the 13th

    11 12 13 * 5
Run at 04:00 every leap year on february 29

    0 4 29 2 *
Run at 04:00 every leap year on february 29 when february 29 is a Thursday

    0 4 29 2 4

Garry Gillies
Database Administrator
Business Systems
Weir Pumps Ltd
149 Newlands Road, Cathcart, Glasgow, G44 4EX

T: +44 0141 308 3982
F: +44 0141 633 1147
E: g.gillies_at_weirpumps.com

------_=_NextPart_001_01C3511D.F9CCC707
Content-Type: text/html;

        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2654.19">
<TITLE>RE: DBMS_JOB scheduling</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2>Garry,</FONT>
</P>

<P><FONT SIZE=3D2>1. have you tried select to_char(sysdate,'D') from =
dual ??</FONT>
</P>

<P><FONT SIZE=3D2>This is really nice, but my only gripe with dbms-job =
is that is isn't reliable ... it wasn't in 9ir1 on aix and we didn't = even look at it in 9ir2. in 9ir1 dbms_job used to _forget_ to run jobs = after some time and the workaround was like setting job_processes to a = very large number.</FONT></P>

<P><FONT SIZE=3D2>nevertheless, I think what you have attempted is =
fantastic and worthy of adoption ...</FONT>
</P>

<P><FONT SIZE=3D2>Raj</FONT>
<BR><FONT =

SIZE=3D2>---------------------------------------------------------------=
-----------------</FONT>

<BR><FONT SIZE=3D2>Rajendra dot Jamadagni at nospamespn dot com</FONT>
<BR><FONT SIZE=3D2>All Views expressed in this email are strictly =
personal.</FONT>
<BR><FONT SIZE=3D2>QOTD: Any clod can have facts, having an opinion is =
an art !</FONT>
</P>
<BR>

<P><FONT SIZE=3D2>-----Original Message-----</FONT>
<BR><FONT SIZE=3D2>From: Garry Gillies [<A =
HREF=3D"mailto:g.gillies_at_weir.co.uk">mailto:g.gillies_at_weir.co.uk</A>]</F=

ONT>

<BR><FONT SIZE=3D2>Sent: Wednesday, July 23, 2003 5:59 AM</FONT>
<BR><FONT SIZE=3D2>To: Multiple recipients of list ORACLE-L</FONT>
<BR><FONT SIZE=3D2>Subject: DBMS_JOB scheduling</FONT>
</P>
<BR>

<P><FONT SIZE=3D2>Any Interest?</FONT>
</P>

<P><FONT SIZE=3D2>The DBMS_JOB package is supplied by Oracle to allow =
the running of procedures at regular intervals. Unfortunately the = INTERVAL parameter is limited to 128 </FONT></P>

<P><FONT SIZE=3D2>characters, which prevents you from getting very =
complex (user defined functions [in the interval parameter] do not work = well - according to Fuerstein in his book Oracle Built In = Packages).</FONT></P>

<P><FONT SIZE=3D2>The situation is eased somewhat by the fact that the =
NEXT_DATE parameter can be supplied to the procedure as an in/out = parameter - and the procedure can contain whatever code is necessary to = calculate when next to run. This is all very well, but custom coding = scheduling routines can quickly become tedious.</FONT></P>

<P><FONT SIZE=3D2>On the basis of&nbsp; &quot;do it once and get it =
over with&quot; I have written a function called NEXT_DATE which I have = wrapped in a package called CRON.</FONT></P>

<P><FONT SIZE=3D2>There is a Unix program called cron which runs jobs =
on a regular basis. Although the scheduling data supplied to cron is = simple and concise,&nbsp; complex schedules are easy to = specify.</FONT></P>

<P><FONT SIZE=3D2>The NEXT_DATE function takes in a cron schedule =
string and returns the next date that conforms to the schedule - or you = can supply a cron schedule and a date </FONT></P>

<P><FONT SIZE=3D2>and it will return the first date after the supplied =
date that conforms to the schedule. At the moment it is not very = friendly on the error detection front. A&nbsp; VALUE_ERROR is returned = if it deems the cron schedule to be invalid. You will also get a&nbsp; = VALUE_ERROR if the next valid date is more than twenty seven years in = the future. DBMS_OUTPUT is used to display error messages which will = hopefully give&nbsp; you a clue. </FONT></P>

<P><FONT SIZE=3D2>This will be improved if I receive enough complaints =
( and suggestions for&nbsp; improvements).</FONT>
</P>

<P><FONT SIZE=3D2>THE CRON SCHEDULE</FONT>
</P>

<P><FONT SIZE=3D2>A cron schedule consists of five components, each =
separated from the next by a space.</FONT>
<BR><FONT SIZE=3D2>The syntax is identical for all components.</FONT>
<BR><FONT SIZE=3D2>The components represent</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
Minute in Hour</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
Hour in day</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Day =
in month</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
Month in year</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Day =
of Week - A bit of a bugger this one. </FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; In =
Unix land the day numbering runs from 0-6 with 0 being Sunday. In = Oracle the day numbering depends on the setting of = NLS_TERRITORY.</FONT></P>

<P><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I =
have chosen to go with ISO standard&nbsp; 8601:1998 which runs from 1-7 = with 1 being Monday. This is so close to the Unix convention that I can = interpret Unix cron schedules correctly.</FONT></P>

<P><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
Curiously, Oracle do not provide a date format which supplies this = number. The ISO week number is available with the format 'IW', but not = the ISO day number. If you have a field of type date called dt, you can = obtain the ISO day number with ( trunc(dt) - trunc(dt ,'IW') ) + = 1</FONT></P>

<P><FONT SIZE=3D2>A component can consist of an asterisk&nbsp;&nbsp; =
*&nbsp;&nbsp;&nbsp; which represents all valid values or a number of = elements separated by a comma (if only one element is </FONT></P>

<P><FONT SIZE=3D2>supplied, forget the comma). An element can be a =
single number - valid for the component (32 in &quot;Day in month&quot; = is invalid) or two numbers separated by a hyphen&nbsp;&nbsp; = -&nbsp;&nbsp; which represents a range.</FONT></P>

<P><FONT SIZE=3D2>EXAMPLES</FONT>
</P>

<P><FONT SIZE=3D2>Run every hour on the hour</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; 0 * * * *</FONT>
<BR><FONT SIZE=3D2>Run twice every hour, on the hour and on the half =

hour</FONT>

<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; 0,30 * * * *</FONT>
<BR><FONT SIZE=3D2>Run twice every hour, on the hour and on the half =
hour between 08:00 and </FONT>
<BR><FONT SIZE=3D2>16:59</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; 0,30 8-16 * * *</FONT>
<BR><FONT SIZE=3D2>Run twice every hour, on the hour and on the half =
hour between 08:00 and </FONT>
<BR><FONT SIZE=3D2>16:59, Monday to Friday</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; 0,30 8-16 * * 1-5</FONT>
<BR><FONT SIZE=3D2>Run at 11:12 every Friday the 13th</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; 11 12 13 * 5</FONT>
<BR><FONT SIZE=3D2>Run at 04:00 every leap year on february 29</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; 0 4 29 2 *</FONT>
<BR><FONT SIZE=3D2>Run at 04:00 every leap year on february 29 when =
february 29 is a Thursday</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; 0 4 29 2 4</FONT>
</P>

<P><FONT SIZE=3D2>Garry Gillies</FONT>
<BR><FONT SIZE=3D2>Database Administrator</FONT>
<BR><FONT SIZE=3D2>Business Systems</FONT>
<BR><FONT SIZE=3D2>Weir Pumps Ltd</FONT>
<BR><FONT SIZE=3D2>149 Newlands Road, Cathcart, Glasgow, G44 4EX</FONT>
<BR><FONT SIZE=3D2>T: +44 0141 308 3982</FONT>
<BR><FONT SIZE=3D2>F: +44 0141 633 1147</FONT>
<BR><FONT SIZE=3D2>E: g.gillies_at_weirpumps.com</FONT>
</P>

</BODY>
</HTML>

------_=_NextPart_001_01C3511D.F9CCC707--

------=_NextPartTM-000-1774fbea-cef8-443a-b02a-80285259ee4c Content-Type: text/plain;

        name="ESPN_Disclaimer.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;

        filename="ESPN_Disclaimer.txt"

*********************************************************************This e-mail message is confidential, intended only for the named recipient(s) above and may contain information that is privileged, attorney work product or exempt from disclosure under applicable law. If you have received this message in error, or are not the named recipient(s), please immediately notify corporate MIS at (860) 766-2000 and delete this e-mail message from your computer, Thank you.*********************************************************************1
Received on Wed Jul 23 2003 - 08:26:08 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US