I have a Job running on an Oracle 10g DB with a pretty simple execution plan.
BYDAY=MON,TUE,WED,THU,FRI;BYHOUR=6,10,14,18
Now the problem is that we have to change the plan – but just for Mondays. So on Mondays the first job should run at 8 instead of 6. Then like all the others (10, 14, 18).
Whereas from Tuesday to Friday it should run as above.
The easiest way would be to create a second job for the Monday and to remove the Monday from the original job.
This, however, is a problem for our application, as it relies on just one job per import.
So the question is: Is there a way to tell the scheduler to run at 6,10,14,18 o'clock TUE-FRI and 8,10,14,18 on MON with a single job?
I read about specifying a repeat interval with a PL/SQL expression. But I didn't find out if there is way to do it.
Thanks for your help
create a composite schedule, and assign that to the job when you create it.
for example:
begin
dbms_scheduler.create_schedule('MY_SCHED1', repeat_interval =>
'FREQ=DAILY;BYDAY=TUE,WED,THU,FRI;BYHOUR=6,10,14,18');
END;
/
begin
dbms_scheduler.create_schedule('MY_SCHED2', repeat_interval =>
'FREQ=DAILY;BYDAY=MON;BYHOUR=8,10,14,18');
END;
/
begin
dbms_scheduler.create_schedule('MAIN', repeat_interval =>
'MY_SCHED1, MY_SCHED2');
END;
/
now you'd just assign the "MAIN" named schedule to the job instead of the schedule string.
Related
I am looking for a way to increment a date parameter each time the scheduler runs the job.
I have a procedure with one DATE parameter which is used to query a table and generate a report email.
Is there a way to schedule the procedure to run daily and submit an incremented date value on each daily run? For example, job is submitted to start at 8am on Sept 1st, 2020 to run with DATE parameter = '31-AUG-2021'. I am expecting it to run on Sept 2nd with DATE parameter = '01-SEP-2021'.
I tried this and seems it is only submitting the same value on each run.
Any suggestions or advice would be much appricated.
Thank you.
DBMS_SCHEDULER.SET_JOB_ANYDATA_VALUE(
job_name => vJobName,
argument_position => 1,
argument_value => sys.anydata.convertDate(trunc(sysdate)- trunc(vJobStartDate) + to_date(vDateArgumentValue,'dd-MON-yyyy'))
I should create a watchdog that monitor a field in a table every 5 minutes, in Oracle DB. If field has a specific value (a date older than x) an action should be performed.
Is it possible to do it in PL/SQL?
If it's not, I should create a script shell and call it from crontab, or maybe use the Scheduler.
If field has a specific value (a date older than x) an action should be performed.
You could create a TRIGGER. If a new row is inserted such that the date column has a specific value, then you perform some action in the trigger.
Perhaps, you need an AFTER INSERT TRIGGER FOR EACH ROW, since you need to reference the :NEW values.
Here is the link to documentation regarding CREATE TRIGGER.
If you really want to do it as a scheduled job, then you could use DBMS_SCHEDULER. Prior to 10g releases, it was DBMS_JOB.
What you need is to use the DBMS_SCHEDULER package
The DBMS_SCHEDULER package provides a collection of scheduling functions and procedures that are callable from any PL/SQL program. (...)
The Scheduler uses a rich calendaring syntax to enable you to define repeating schedules, such as "every Tuesday and Friday at 4:00 p.m." or "the second Wednesday of every month."
Sorry, maybe I've omitted a detail the field to monitor is for a specific row. I mean if the result of the query:
select up_date from mytab where name_id='test'
is older than 15minutes
then
update mytab set value_col='no' where name_id='test'
But I don't know if it's possible to do it with a trigger. With SCHEDULER I could check at interval time and could be a good work-around.
You may still have a AFTER UPDATE trigger and in that trigger check if the updated row is the one you want to watch. Something like this:
IF :old.name_id = 'test' THEN
-- do something here
END IF;
I have job, created using DBMS_JOB, which runs daily at 1:00 am
WHAT PROC_XYZ();
NEXT_DATE 16-OCT-13
NEXT_SEC 01:00:00
INTERVAL trunc(sysdate)+1+1/24
I want to change it to run at specific dates (with no pattern or fixed interval), for instance: 30 Oct 2013, 14 Nov 2013, 18 Nov 2013
Is there a way I can specify a list of dates for the job to run?
No.
BUT, you can create a list of the dates that you want the job to run and check whether the current date is one of those dates before executing the procedure. The RETURN statement will return control to the invoking code as soon as it's executed in a procedure.
So, add something like this to the first executed line of your procedure:
if trunc(sysdate) not in (date '2013-10-30', date '2013-11-14') then
return;
end if;
I would probably use a table rather than a list of dates so it's easy to modify without changing code. If you run the job every day then it will exit immediately all days but those you want to it to run completely.
It's worth reading the note at the top of the DBMS_JOB docs:
The DBMS_JOB package has been superseded by the DBMS_SCHEDULER package. In particular, if you are administering jobs to manage system load, you should consider disabling DBMS_JOB by revoking the package execution privilege for users.
![enter image description here][1]
I just updated with a new version of the database. I've previously used Oracle database versioyon 10. Now I installed Oracle 11g Express edition.
I had the three jobs on the DBMS_jobs.
I programmed it to run them at a particular time on a daily basis. every day at 01:00 in the stored procedure was running on a regular basis.
begin
sys.dbms_job.submit(job => :job,
what => 'BEGIN CALL_MY_SP; END;',
next_date => to_date('24-09-2013 01:00:00', 'dd-mm-yyyy hh24:mi:ss'),
interval => 'TRUNC(SYSDATE + 1) + 1/24');
commit;
end;
Although the same job to the new Oracle database running. But this job is manually executing.
How do I run automatically on a regular basis every day? But What if I did not!
http://i.stack.imgur.com/rePVq.png
your job
http://l1309.hizliresim.com/1f/s/sz6pg.png
To run manually, try:
exec dbms_scheduler.run_job('MY_JOB',false);
and to stop manually, use:
exec dbms_scheduler.stop_job('MY_JOB',false);
If your question is how to scheduler a job in Oracle, its a big topic (see Documentation ), but a simple example would be:
BEGIN
dbms_scheduler.create_job(
job_name=>'JOB_TEST2',
job_type=>'PLSQL_BLOCK',
job_action=>'BEGIN
dbms_lock.sleep(10);
END;',
start_date=>systimestamp,
repeat_interval=>'FREQ=MINUTELY;INTERVAL=1',
number_of_arguments=>0,
enabled=>TRUE,
comments=>'Job duration is 10 seconds, launches every minute'
);
END;
Since it was created as enabled, it will start running automatically. You can verify this looking at the logs (dba_scheduler_job_run_details) and can view basic attributes via dba_scheduler_jobs
I have stored procedure.In procedure there are three cursors.I have to run procedure daily in production.I want only two cursors should run daily and the remaining cursor should run only on 1st of every month.So what are the changes should be made to third cursor.Please provide the solution.
The cursor itself doesn't actually run. It is your code that uses the cursor. So you can check in code if it is the first day of the month:
-- Check if today is first day of the month
if trunc(sysdate, 'MM') = trunc(sysdate) then
-- Use cursor here
end if;
Possibly a better solution is to create two separate procedures and create jobs for each of them. You can specify intervals for the job so one runs daily while the other runs monthly.
Look into dbms_scheduler