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: Igor Neyman <ineyman_at_perceptron.com>
Date: Wed, 23 Jul 2003 09:41:33 -0400
Message-Id: <25998.339116@fatcity.com>


This is a multi-part message in MIME format.

------=_NextPart_000_0029_01C350FE.9A434140 Content-Type: text/plain;

        charset="US-ASCII"
Content-Transfer-Encoding: 7bit

Raj,  

You must be speaking from "UNIX heights" -:-)

Under Windows I find dbms_job much more reliable than windows "at" scheduling.

Actually, never had problems with dbms_job "forgetting" to run a job.  

Igor Neyman, OCP DBA

ineyman_at_perceptron.com    

-----Original Message-----
From: ml-errors_at_fatcity.com [mailto:ml-errors_at_fatcity.com] On Behalf Of Jamadagni, Rajendra
Sent: Wednesday, July 23, 2003 9:24 AM
To: Multiple recipients of list ORACLE-L Subject: RE: DBMS_JOB scheduling  

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_000_0029_01C350FE.9A434140 Content-Type: text/html;

        charset="US-ASCII"
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=3DUS-ASCII">

<meta name=3DGenerator content=3D"Microsoft Word 10 (filtered)">
<title>RE: DBMS_JOB scheduling</title>

<style>
<!--

 /* Font Definitions */
 @font-face

	{font-family:Wingdings;
	panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}

 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:blue;
	text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:10.0pt;
	font-family:"Courier New";}
p
	{margin-right:0in;
	margin-left:0in;
	font-size:12.0pt;
	font-family:"Times New Roman";}
span.EmailStyle18
	{font-family:Arial;
	color:navy;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
	{page:Section1;}

-->
</style>

</head>

<body lang=3DEN-US link=3Dblue vlink=3Dblue>

<div class=3DSection1>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Raj,</span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>&nbsp;</span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>You must be speaking from = &#8220;UNIX
heights&#8221; -</span></font><font size=3D2 color=3Dnavy = face=3DWingdings><span
style=3D'font-size:10.0pt;font-family:Wingdings;color:navy'>J</span></fon= t></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Under Windows I find dbms_job much = more
reliable than windows &#8220;at&#8221; scheduling.</span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Actually, never had problems with = dbms_job
&#8220;forgetting&#8221; to run a job.</span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>&nbsp;</span></font></p>

<div>

<p class=3DMsoPlainText><font size=3D2 color=3Dnavy face=3D"Courier =
New"><span
style=3D'font-size:10.0pt;color:navy'>Igor Neyman, OCP = DBA</span></font></p>

<p class=3DMsoPlainText><font size=3D2 color=3Dnavy face=3D"Courier =
New"><span
 =
style=3D'font-size:10.0pt;color:navy'>ineyman_at_perceptron.com</span></font= ></p>

<p class=3DMsoPlainText><font size=3D2 color=3Dnavy face=3D"Courier =
New"><span
style=3D'font-size:10.0pt;color:navy'>&nbsp;</span></font></p>

</div>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>&nbsp;</span></font></p>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D2 =
face=3DTahoma><span
style=3D'font-size:10.0pt;font-family:Tahoma'>-----Original = Message-----<br>
<b><span style=3D'font-weight:bold'>From:</span></b> =
ml-errors_at_fatcity.com
[mailto:ml-errors_at_fatcity.com] <b><span style=3D'font-weight:bold'>On = Behalf Of </span></b>Jamadagni,
Rajendra<br>
<b><span style=3D'font-weight:bold'>Sent:</span></b> Wednesday, July 23, =
2003
9:24 AM<br>
<b><span style=3D'font-weight:bold'>To:</span></b> Multiple recipients =
of list
ORACLE-L<br>
<b><span style=3D'font-weight:bold'>Subject:</span></b> RE: DBMS_JOB =
scheduling</span></font></p>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D3 =
face=3D"Times New Roman"><span
style=3D'font-size:12.0pt'>&nbsp;</span></font></p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>Garry,</span></font> </p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>1. have you tried select to_char(sysdate,'D') = from
dual ??</span></font> </p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>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.</span></font></p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>nevertheless, I think what you have attempted = is fantastic
and worthy of adoption ...</span></font> </p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>Raj</span></font> <br>
<font size=3D2><span =

style=3D'font-size:10.0pt'>----------------------------------------------=
----------------------------------</span></font>

<br>
<font size=3D2><span style=3D'font-size:10.0pt'>Rajendra dot Jamadagni =
at
nospamespn dot com</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>All Views expressed in =
this email
are strictly personal.</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>QOTD: Any clod can have =
facts, having
an opinion is an art !</span></font> </p>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D3 =
face=3D"Times New Roman"><span
style=3D'font-size:12.0pt'>&nbsp;</span></font></p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>-----Original Message-----</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>From: Garry Gillies [<a
href=3D"mailto:g.gillies_at_weir.co.uk">mailto:g.gillies_at_weir.co.uk</a>]</sp= an></font>
<br>
<font size=3D2><span style=3D'font-size:10.0pt'>Sent: Wednesday, July =
23, 2003 5:59
AM</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>To: Multiple recipients =
of list
ORACLE-L</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>Subject: DBMS_JOB =
scheduling</span></font>
</p>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D3 =
face=3D"Times New Roman"><span
style=3D'font-size:12.0pt'>&nbsp;</span></font></p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>Any Interest?</span></font> </p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>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 </span></font></p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>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).</span></font></p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>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.</span></font></p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>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.</span></font></p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>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.</span></font></p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>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 </span></font></p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>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. =
</span></font></p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>This will be improved if I receive enough = complaints (
and suggestions for&nbsp; improvements).</span></font> </p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>THE CRON SCHEDULE</span></font> </p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>A cron schedule consists of five components, = each
separated from the next by a space.</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>The syntax is identical =
for all
components.</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>The components =
represent</span></font>
<br>
<font size=3D2><span =

style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs= p;
Minute in Hour</span></font> <br>
<font size=3D2><span =

style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs= p;
Hour in day</span></font> <br>
<font size=3D2><span =

style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs= p;
Day in month</span></font> <br>
<font size=3D2><span =

style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs= p;
Month in year</span></font> <br>
<font size=3D2><span =

style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs= p;
Day of Week - A bit of a bugger this one. </span></font><br>
<font size=3D2><span =

style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs= p;
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.</span></font></p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs= p; 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.</span></font></p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs= p;
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</span></font></p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>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 </span></font></p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>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.</span></font></p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>EXAMPLES</span></font> </p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>Run every hour on the hour</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp; =
0 * * * *</span></font>
<br>
<font size=3D2><span style=3D'font-size:10.0pt'>Run twice every hour, on =
the hour
and on the half hour</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp; =
0,30 * * *
*</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>Run twice every hour, on =
the hour
and on the half hour between 08:00 and </span></font><br>
<font size=3D2><span style=3D'font-size:10.0pt'>16:59</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp; =
0,30 8-16
* * *</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>Run twice every hour, on =
the hour
and on the half hour between 08:00 and </span></font><br>
<font size=3D2><span style=3D'font-size:10.0pt'>16:59, Monday to =
Friday</span></font>
<br>
<font size=3D2><span style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp; 0,30 =
8-16 * * 1-5</span></font>
<br>
<font size=3D2><span style=3D'font-size:10.0pt'>Run at 11:12 every =
Friday the 13th</span></font>
<br>
<font size=3D2><span style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp; 11 12 =
13 * 5</span></font>
<br>
<font size=3D2><span style=3D'font-size:10.0pt'>Run at 04:00 every leap =
year on
february 29</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp; 0 4 =
29 2 *</span></font>
<br>
<font size=3D2><span style=3D'font-size:10.0pt'>Run at 04:00 every leap =
year on
february 29 when february 29 is a Thursday</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp; 0 4 =
29 2 4</span></font>
</p>

<p style=3D'margin-left:.5in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>Garry Gillies</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>Database =
Administrator</span></font>
<br>
<font size=3D2><span style=3D'font-size:10.0pt'>Business =
Received on Wed Jul 23 2003 - 08:41:33 CDT

Original text of this message

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