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'))
Related
I am using a stored procedure to write the date and time in a file. Also, I have scheduled my procedure to 1 AM daily.
My code to get the date and time is
select to_char(CURRENT_TIMESTAMP,'DDMMYYYY/HH:MI:SS') from dual;
But, the displayed date was the previous day's date. Will sysdate() works in this place correctly?
Why is the last start date sometimes bigger than the next run dat in the Oracle jobs log?
When you select values in the ALL_SCHEDULER_JOBS table:
select * from ALL_SCHEDULER_JOBS
Sometimes the last start date is bigger than the next run date. For example, the last start date is:
2015/08/11 16:20:00.155707 +08:00
and next run date is:
2015/08/11 16:20:00.000000 +08:00
Why is this the case?
It means that the job is now running and the new value for the next run will be set after the current run finishes.
I'm currently working on an assignment where I have to port some Oracle scripts to MS SQL. I ran into a problem at the scheduled jobs. The Oracle script looks like this:
dbms_job.submit(job =>v_job,
what =>'begin pkg_report.REFRESH_MVIEWS; end;',
next_date =>Trunc(sysdate, 'HH24')+70/1440, interval =>'Trunc(sysdate, ''HH24'')+70/1440');
dbms_job.submit(job =>v_job, what =>'begin pkg_housekeeping.cleanup_daily; end;', next_date =>trunc(sysdate)+1, interval =>'trunc(sysdate)+1+1/24');
The problem is, I don't understand what this truncing is supposed to do. I tried to replicate it in SQL Developer, played around with it a bit, most of the format strings have very obvoius outcome (YEAR, MONTH, ...), but I don't know what HH24 is supposed to do. And what's with the +70/1440, +1, +1+1/24 suffixes at the end?
I'd appreciate a little help. Thanks in advance!
TRUNC removes the time element of the current date, so the code sets the date to midnight of today (sysdate) and then adds 70/1440 of a day to it.
70/1440 of a day is 01:10 (ten past one in the morning)
+1+1/24 adds one day and 1/24th of a day, so 1am the following day
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.
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.