Oracle Job Scheduler doesn't repeat the job_action - oracle

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.

Related

oracle scheduler job not running (after enabling it)

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;

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');

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;
/

What is the syntax for adding parameters to the called procedure in Oracle scheduler?

So say I have 2 procedures: MYPROC1 & MYPROC2(A_PARAM INTEGER)
this works:
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'TEST_SCHEDULER',
job_type => 'STORED_PROCEDURE',
job_action => 'developer.MYPROC1', <<<<<<<<<<<<<<<
start_date => TIMESTAMP'2011-12-4 10:30:00',
repeat_interval => 'FREQ=SECONDLY;INTERVAL=30',
end_date => TIMESTAMP'2011-12-4 10:45:00',
auto_drop => FALSE,
comments => 'TEST 1');
END;
replacing line 5 with:
job_action => 'developer.MYPROC1(2)' makes it not work.
Error: ..invalid name for a database object...
So how do I call from a scheduler a parametrized procedure? Whats the syntax?
use job_type => 'PLSQL_BLOCK', job_action => 'BEGIN developer.MYPROC1(2); END;' instead.
Leave your job_action parameter as it is (without the arguments), and add the number_of_arguments option to the number if parameters your procedure expects.
You can then use DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE to set the argument values.
Examples here: Using jobs.
Firsly, create your scheduler job by using DBMS_SCHEDULER.CREATE_JOB without enabling (default is false, already), and then that should be enabled to run.
It' nice to define job_name parameter as a bind variable for consecutive job names.
job_name parameter needn't to be in upper cases, but when querying scheduler run history, call it with all letters of job_name in upper from a privileged schema :
select *
from dba_scheduler_job_log l
where l.job_name = 'TEST_SCHEDULER'
order by l.log_date desc;
Don't forget to include number_of_arguments(for this case it equals 1) parameter for your job creation command.
As Mat tells you may use DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE like in the following example ( also define argument value parameter as a bind variable with value 2 as in your case ) :
BEGIN
DBMS_SCHEDULER.CREATE_JOB(
job_name => '&v_job_name', -- tEst_sCheDuLEr
job_type => 'STORED_PROCEDURE',
job_action => 'developer.MYPROC1',
number_of_arguments => 1,
start_date => '04-apr-2018 10:30:00 am',
repeat_interval => 'FREQ=SECONDLY;INTERVAL=3;',
end_date => '04-apr-2018 10:45:00 am',
auto_drop => false,
comments => 'TEST 1');
DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE(
job_name => '&v_job_name',
argument_position => 1,
argument_value => &vl -- 2
);
DBMS_SCHEDULER.ENABLE('&v_job_name');
END;
If you get ORA-01882 Timezone region not found error, then
to_timestamp_tz('04-APR-2018 10:30:00 EST', 'DD-MON-YYYY HH24:MI:SS TZR')
or to_date('04.04.2018 10:30:00', 'DD.MM.YYYY HH24:MI:SS')
format may be used for start_date parameter.

Resources