oracle scheduler job not running (after enabling it) - oracle

I created a scheduler job in the following way:
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'update_sales_1',
job_type => 'STORED_PROCEDURE',
job_action => 'test_job',
start_date => systimestamp,
repeat_interval => 'FREQ=SECONDLY;INTERVAL=10',
end_date => '20-NOV-2021 07.00.00 PM Australia/Sydney',
auto_drop => FALSE,
comments => 'My new job');
END;
/
The stored procedure test_job inserts record into a table.
After creating the JOB, I enabled it and waited for 20 seconds and checked the table.
I do not see the records inserted.

You should add a parameter enabled => TRUE, default is FALSE.
If you want to enable the job after creating it you can also use:
DBMS_SCHEDULER.ENABLE(name => 'update_sales_1');
If your job did run, and you don't see anything that has happened you might can look at the job run details if something went wrong:
SELECT * FROM dba_scheduler_job_run_details WHERE job_name = UPPER('update_sales_1') ORDER BY actual_start_date;

Related

Oracle Job deleted after execution

I'm on oracle 11g
I created a job named "MyJob" to be ran at a fixed date/hour.
The job is well created.
When the job is executed correctly at the fixed date/hour, the job is apparently deleted from the table dba_scheduler_jobs, I verified with this query:
SELECT owner, job_name, enabled FROM dba_scheduler_jobs;
My question is why the job is "deleted" ?
My job creation script:
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'MyJobTest',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN insert into test values (''01'',sysdate); END;',
start_date => '01/12/16 17:00:00,000000000 +01:00',
repeat_interval => NULL,
end_date => NULL,
enabled => TRUE,
comments => ' Insert into Test Table');
END;
/
Thanks in advance.
If you don't specify a repeat_interval and the auto_drop parameter is set to true (the default if you don't specify the parameter at all), Oracle will drop the job once it is run. Generally, if you're creating a job that runs once, there is no point in leaving it around forever.
You can tell Oracle not to auto drop the job by specifying an auto_drop value of false.
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'MyJobTest',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN insert into test values (''01'',sysdate); END;',
start_date => '01/12/16 17:00:00,000000000 +01:00',
repeat_interval => NULL,
end_date => NULL,
enabled => TRUE,
auto_drop => false,
comments => ' Insert into Test Table');

what if there is no repeat_interval in dbms_scheduler.create_job

I have created a Job using this.
BEGIN
dbms_scheduler.create_job (
job_name => 'test_JOB',
job_type => 'PLSQL_BLOCK',
JOB_ACTION => 'UP_TRYNR;',
start_date =>sysdate,
enabled => true,
repeat_interval => 'FREQ=DAILY;INTERVAL=1'
);
END;
If I create the job without specifying repeat_interval what will happen? i.e.
BEGIN
dbms_scheduler.create_job (
job_name => 'test_JOB',
job_type => 'PLSQL_BLOCK',
JOB_ACTION => 'UP_TRYNR;',
start_date =>sysdate,
enabled => true,
);
END;
Any suggestion will be helpful. Thanks.
The DBMS_SCHEDULER package includes functionality that can be used to set up and manage the timetabling and execution of tasks that need to be run according to a – repeating or non-repeating – schedule.
DBMS_SCHEDULER breaks the process of scheduling a task into 3 parts:
Create a schedule
Identify a ‘program’ – by which they mean the procedure you wish to
run
Create a ‘job’ – by which they mean chain a program to a schedule.
As name suggests Repeat_interval,describes the frequency when the programs needs to be executed. This is a bit like the cron syntax in UNix.
If you create it without any Repeat_interval,it would execute only once at the specified startdate and then remain dormant.

Oracle Job Scheduler doesn't repeat the job_action

I want to repeate a Job every 5 minutes. I have a test table that I fill with random dates. If there are dates older then SYSDATE-5, than I want to delete them. The following code works only the first time I start the scheduler and it never repeats the job_action agaian:
BEGIN
SYS.DBMS_SCHEDULER.CREATE_JOB (
job_name => '"AUTHMGR"."Test2"',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN DELETE FROM TEST WHERE TESTDATE < SYSDATE-5;END;',
number_of_arguments => 0,
start_date => SYSDATE,
repeat_interval => 'FREQ=MINUTELY;INTERVAL=5',
end_date => NULL,
job_class => '"SYS"."DEFAULT_JOB_CLASS"',
enabled => TRUE,
auto_drop => FALSE,
comments => 'Test');
END;
/
Do I use the repeat_interval with wrong FREQ and wrong INTERVAL?
I use the Scheduler in Oracle SQL Developer.
The problem was with the INSERT statements. There was no COMMIT after INSERT.

DBMS SCHEDULER Job with input

Hi I have a stored procedure in oracle that I would like to run periodically. Firstly I got my DBMS_SCHEDULER Job to compile (see below) and I can even see the job be created and drop it though I don't see the result of the stored procedure occur in the table it is supposed to effect and the stored procedure has been tested.
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'JOB_QUERY',
job_type => 'PLSQL_BLOCK', -- see oracle documentation on types --
job_action => 'BEGIN RUNREPORT(''NAME'', ''VERSION'', ''04-Jun-13'', ''11-Jun-13''); END;',
start_date => to_date('2013-08-19 16:35:00', 'YYYY-MM-DD HH24:MI:SS' ),
repeat_interval => 'FREQ=MINUTELY;BYMINUTE=10', -- every 10 minutes.
end_date => NULL,
enabled => TRUE,
comments => 'Daily Jira Query Update');
END;
I was attempting to simply make it run every ten minutes though I see no changes. Also I wanted to be able to pass SYSDATE or the current date to the procedure in the dbms_scheduler job but I cant get it to work with the apostrophes.
Thanks
You have to COMMIT your DML statements. There is no COMMIT in PL/SQL block and I guess in procedure RUNREPORT either.
You don't need an apostrophe around sysdate, it's not a string literal.
job_action => 'BEGIN RUNREPORT(''NAME'', ''VERSION'', sysdate, ''11-Jun-13''); COMMIT; END;',
BYMINUTE does not mean what you would expect. From documentation:
"This specifies the minute on which the job is to run. Valid values are 0 to 59. As an example, 45 means 45 minutes past the chosen hour". What you need is
repeat_interval => 'FREQ=MINUTELY;INTERVAL=10'
You can check next run date and more by querying user_scheduler_jobs.
If you are calling the stored procedure from DMBS Scheduled job you can try below.
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
JOB_NAME => 'SCHEMA.MY_DBMS_SCHEDULED_JOB',
JOB_TYPE => 'STORED_PROCEDURE',
JOB_ACTION => 'SCHEMA.STORED_PROCEDURE_TO_BE_CALLED',
START_DATE => '01-AUG-13 12.00.00 AM',
REPEAT_INTERVAL => 'FREQ=DAILY;BYHOUR=0;BYMINUTE=10',
AUTO_DROP => FALSE,
ENABLED => TRUE,
NUMBER_OF_ARGUMENTS => 0,
COMMENTS => 'Scheduled job to perform updates.');
END;
/
To see if your scheduler log you can use below query.
SELECT * FROM all_SCHEDULER_JOB_LOG
where job_name='MY_DBMS_SCHEDULED_JOB'
order by log_id desc;

job scheduling for a few hours everyday

I need to schedule a job starting from 0600 till 1800. The job should run after every two hours. For example 0800, 1000, 1200, 1400, 1600, 1800.
Here is the code I have managed to do so far:
DECLARE
l_id binary_integer;
begin
sys.dbms_job.submit(job => l_id, what => 'integration_export;', interval => 'TRUNC(SYSDATE,''hh24'')+0/24/60');
sys.dbms_output.put_line(l_id);
end;
This will, of course, run the job after every 2 hours without stopping at 1801 - 0759. How may I add this restriction?
One thing I though is to create another schedule procedure which wakes up at 1801 and changes NEXT_DATE for this job. However, I am wondering if it is a good idea.
Any suggestions?
Thanks in advance :-)
dbms_job is old. I'd recomend you use the dbms_scheduler (introduced in Oracle 10g) instead.
dbms_scheduler.create_job(job_name => 'YOUR_JOB',
job_type => 'PLSQL_BLOCK',
job_action => 'integration_export;',
start_date => systimestamp,
repeat_interval => 'freq=hourly; byhour=8,10,12,14,16,18; byminute=0; bysecond=0;',
enabled => true,
auto_drop => false,
comments => 'some comment about the job');
Instead of dmbs_job, use the advanced dbms_scheduler. Here is an example:
begin
DBMS_SCHEDULER.create_job (
job_name => 'Integration_export',
job_type => 'PLSQL_BLOCK',
job_action => 'integration_export;',
start_date => SYSTIMESTAMP,
enabled => TRUE,
repeat_interval => 'freq=daily; byhour=6,8,10,12,14,16,18; byminute=0; bysecond=0');
end;
/

Resources