Why this Oracle job is only executed once? - oracle

I've an Oracle job defined as follows:
BEGIN
DBMS_SCHEDULER.drop_job('clean_journal_partitions');
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'clean_journal_partitions',
job_type => 'STORED_PROCEDURE',
job_action => 'CLEAN_JOURNAL_PARTITION',
repeat_interval => 'FREQ=WEEKLY;BYDAY=MON',
auto_drop => FALSE);
DBMS_SCHEDULER.ENABLE('clean_journal_partitions');
END;
That if I'm not wrong, it should be executed once a week every monday. The problem is that it is executed only once and I don't know why.
To be able to test it more easily, I've modified it to change the frequency from weekly to every 10 seconds, like this:
BEGIN
DBMS_SCHEDULER.drop_job('clean_journal_partitions');
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'clean_journal_partitions',
job_type => 'STORED_PROCEDURE',
job_action => 'CLEAN_JOURNAL_PARTITION',
repeat_interval => 'FREQ=SECONDLY;INTERVAL=10',
auto_drop => FALSE);
DBMS_SCHEDULER.ENABLE('clean_journal_partitions');
END;
And I've the same problem. It is executed only once. Any hint why the job is not executed every 10 seconds?

This works fine for me in Oracle 11g:
CREATE TABLE TEST(
run_time DATE
);
CREATE OR REPLACE PROCEDURE CLEAN_JOURNAL_PARTITION AS
BEGIN
INSERT INTO TEST VALUES(SYSDATE);
COMMIT;
END;
/
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'clean_journal_partitions',
job_type => 'STORED_PROCEDURE',
job_action => 'CLEAN_JOURNAL_PARTITION',
repeat_interval => 'FREQ=SECONDLY;INTERVAL=10',
auto_drop => FALSE);
DBMS_SCHEDULER.ENABLE('clean_journal_partitions');
END;
I get one entry in the TEST table every 10 seconds. Your problem must be in your CLEAN_JOURNAL_PARTITION procedure, maybe it crashes?

Related

DBMS Scheduler error: ORA-27367: program "Schema.PROG_programname" associated with this job is disabled

I have created an oracle job using dbms scheduler.But the status gets failed in the execution. It gives the following error. 'ORA-27367: program "Schema.PROG_SIXMONTHPRIORITY" associated with this job is disabled' But I do not have disabled the job. 'program_action => 'SIXMONTHPRIORITY'' is a procedure that I have created in the schema. When I execute that procedure separately, it gets executed.
BEGIN
DBMS_SCHEDULER.CREATE_PROGRAM (
program_name => 'PROG_SIXMONTHPRIORITY',
program_action => 'SIXMONTHPRIORITY',
program_type => 'STORED_PROCEDURE');
END;
BEGIN
DBMS_SCHEDULER.CREATE_SCHEDULE (
schedule_name => 'P_SCHEDULE_3',
start_date => SYSTIMESTAMP,
repeat_interval => 'FREQ= MINUTELY; INTERVAL=30; BYMONTHDAY=19; BYHOUR=13',
end_date => SYSTIMESTAMP + INTERVAL '1' day,
comments => 'Every 30 minutes');
END;
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'CAL_SIX_MON_PRIORITY_3',
program_name => 'PROG_SIXMONTHPRIORITY',
schedule_name => 'P_SCHEDULE_3');
END;
Can anyone identify the reason for this error?
The Scheduler objects that you created can also be separately enabled or disabled. Make sure to specify "enabled => true" when creating scheduler objects:
BEGIN
DBMS_SCHEDULER.CREATE_PROGRAM (
program_name => 'PROG_SIXMONTHPRIORITY',
program_action => 'SIXMONTHPRIORITY',
program_type => 'STORED_PROCEDURE',
enabled => true);
END;
BEGIN
DBMS_SCHEDULER.CREATE_SCHEDULE (
schedule_name => 'P_SCHEDULE_3',
start_date => SYSTIMESTAMP,
repeat_interval => 'FREQ= MINUTELY; INTERVAL=30; BYMONTHDAY=19; BYHOUR=13',
end_date => SYSTIMESTAMP + INTERVAL '1' day,
comments => 'Every 30 minutes');
END;
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'CAL_SIX_MON_PRIORITY_3',
program_name => 'PROG_SIXMONTHPRIORITY',
schedule_name => 'P_SCHEDULE_3',
enabled => true);
END;
For existing objects, you can set the attributes directly:
BEGIN
DBMS_SCHEDULER.ENABLE ('PROG_SIXMONTHPRIORITY');
DBMS_SCHEDULER.ENABLE ('CAL_SIX_MON_PRIORITY_3');
END;
/

DBMS_SCHEDULER in apex oracle

I have an API package written. It has the GET_INFO procedure. I want this procedure to be performed in the background every 20 minutes. I understand what I should do with dbms_scheduler. But in general I do not understand where to register them . I will be grateful for the example or for your help with this)
I wrote such a code but I don't know where to use it:
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name = 'My_Job',
job_type = 'STORED_PROCEDURE',
job_action = 'INSERT INTO TEST2(UPDATEDAT)
VALUES (sysdate);
END;',
start_date = 'systimestamp',
repeat_interval = 'FREQ=SECONDLY;INTERVAL=5',
end_date = null,
auto_drop = FALSE,
comments = 'My new job');
END;
Here is my code and I don't know where to store it.
As the job type implies, you need a procedure to be created such as
create or replace procedure Ins_Test2 is
begin
insert into Test2(updatedat) values(sysdate);
commit;
end;
and then create the scheduler through
begin
dbms_scheduler.create_job (
job_name => 'My_Job',
job_type => 'STORED_PROCEDURE',
job_action => 'Ins_Test2',
start_date => systimestamp,
repeat_interval => 'freq=minutely; interval = 20; byday=MON,TUE,WED,THU,FRI;',
enabled => true,
comments => 'My new job'
);
end;
where I added
byday=MON,TUE,WED,THU,FRI; as an extra direction if you want to run
the scheduler within the working days(you can omit that part if you'd
like).
systimestamp(get rid of quotes) for start_date might be
replaced with an upcoming time info such as start_date => '13-FEB-20 2.00.00PM Asia/Istanbul'
in my case.
And follow by listing the created schedulers by
select job_name, next_run_date
from dba_scheduler_jobs j;
And currently running ones by
select *
from user_scheduler_job_log l
order by l.log_date desc;
And drop the scheduler by
begin
dbms_scheduler.drop_job( job_name => 'My_Job' );
end;

How to rename scheduler job Oracle

I would like rename scheduler job in Oracle, is it possible?
dba_scheduler_jobs(owner = "db", name = "my_job")
=> dba_scheduler_jobs(owner = "db", name = "my_own_job");
Thanks for answers.
A job is a database object, so the RENAME command works natively
SQL> begin
2 dbms_scheduler.create_job (
3 job_name => 'MY_BAD_NAME',
4 job_type => 'PLSQL_BLOCK',
5 job_action => 'begin null; end;',
6 start_date => systimestamp,
7 repeat_interval => 'freq=hourly; byminute=0; bysecond=0;',
8 enabled => true);
9 end;
10 /
PL/SQL procedure successfully completed.
SQL> rename MY_BAD_NAME to BETTER_NAME;
Table renamed.
SQL> select job_name from user_scheduler_jobs;
JOB_NAME
--------------------------------------------------------------------------------
BETTER_NAME
Instead of rename, you can create/replicate job and drop the old one.
Below, my_new_job1 has created.
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'my_new_job1',
program_name => 'my_saved_program',
repeat_interval => 'FREQ=DAILY;BYHOUR=12',
comments => 'Daily at noon');
END;
/
Below, my_new_job2 has created with same details as my_new_job1
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'my_new_job2',
program_name => 'my_saved_program',
repeat_interval => 'FREQ=DAILY;BYHOUR=12',
comments => 'Daily at noon');
END;
/
Below an old job my_new_job1 has been deleted.
BEGIN
DBMS_SCHEDULER.DROP_JOB ('my_new_job1');
END;
/

How do I schedule a stored procedure to run daily at certain time?

I am trying to schedule a stored procedure in Oracle, it should run daily at a certain time, for example at 11:59 pm
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'BLANKET_WO',
job_type => 'STORED_PROCEDURE',
job_action => 'AAKPID.BLANKET_WO_PROC',
repeat_interval => 'FREQ=DAILY;BYHOUR=23;BYMINUTE=59');
END;
/
Will this code work?
Try this, it should work:
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'BLANKET_WO',
job_type => 'STORED_PROCEDURE',
job_action => 'AAKPID.BLANKET_WO_PROC',
start_date => '16-nov-2017 11:50:00 pm',
repeat_interval => 'FREQ=DAILY;BYHOUR=23;BYMINUTE=59',
enabled => true
);
END;
/

Chaining multiple procedures in oracle

I have 2 stored procedures, and I want to schedule it in such a way that the first procedure will run on once particular time, and once it completes execution, the second one should start running.
Is it possible on oracle?
For example:
BEGIN
DBMS_SCHEDULER.CREATE_JOB(
job_name => 'job1',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN
proc1;
proc2;
END;',
start_date => SYSDATE, --whatever dat you want
repeat_interval => 'FREQ = DAILY; INTERVAL = 1' --whatever interval you want
);
END;
/
Read more here: http://docs.oracle.com/cd/E11882_01/server.112/e25494/appendix_a.htm#ADMIN12510

Resources