I am trying to create an event based job using oracle dbms_scheduler as described below. Is there a way we can pass the job information that raised the event into the job that is executed based on that event.
Subscribing to the queue
BEGIN
sys.DBMS_SCHEDULER.add_event_queue_subscriber ('my_queue_agent');
END;
Create program that will be called by the first job
begin
sys.dbms_scheduler.create_program(program_name => 'PROGRAM_TEST',
program_type => 'STORED_PROCEDURE',
program_action => 'PROC_TEST_SCHEDULER',
number_of_arguments => 2,
enabled => false,
comments => '');
sys.dbms_scheduler.define_program_argument(program_name => 'PROGRAM_TEST',
argument_position => 1,
argument_name => 'P_JOB_NAME',
argument_type => 'VARCHAR2',
default_value => '');
sys.dbms_scheduler.define_metadata_argument(program_name => 'PROGRAM_TEST',
metadata_attribute => 'LOG_ID',
argument_position => 2,
argument_name => 'LOG_ID');
sys.dbms_scheduler.enable(name => 'PROGRAM_TEST');
end;
Create job that utilizes the program.
begin
sys.dbms_scheduler.create_job(job_name => 'TEST_PROGRAM_JOB',
program_name => 'PROGRAM_TEST',
start_date => to_date(null),
repeat_interval => '',
end_date => to_date(null),
job_class => 'DEFAULT_JOB_CLASS',
enabled => false,
auto_drop => false,
comments => '');
sys.dbms_scheduler.set_job_argument_value(job_name => 'TEST_PROGRAM_JOB',
argument_name => 'P_JOB_NAME',
argument_value => 'TEST_PROGRAM_JOB');
sys.dbms_scheduler.set_attribute(name => 'TEST_PROGRAM_JOB', attribute => 'raise_events', value => sys.dbms_scheduler.job_started + sys.dbms_scheduler.job_succeeded + sys.dbms_scheduler.job_failed);
end;
Create second job that would be triggered based on events of first job.
BEGIN
sys.DBMS_SCHEDULER.create_job (
job_name => 'UPDATE_STATUS_JOB',
job_type => 'PLSQL_BLOCK',
job_action => 'insert into t_log values (''UPDATE'' || tab.user_data.log_id,sysdate);',
event_condition => '(tab.user_data.event_type = ''JOB_SUCCEEDED'' OR
tab.user_data.event_type = ''JOB_FAILED'' or
tab.user_data.event_type = ''JOB_STARTED'' or
tab.user_data.event_type = ''JOB_COMPLETED'') AND tab.user_data.object_name = ''TEST_PROGRAM_JOB''',
queue_spec => 'sys.scheduler$_event_queue,my_queue_agent',
enabled => TRUE);
END;
Is there a way I can pass the current log_id of TEST_PROGRAM_JOB into UPDATE_STATUS_JOB? I want to log the status of the TEST_PROGRAM_JOB. Right now, I tried using tab.user_data.log_id but with no success.
sys.dbms_scheduler.define_metadata_argument only works with 'job_name', 'job_subname', 'job_owner', 'job_start', 'window_start', 'window_end', and 'event_message.
In your case try to use event_message. You can also replace p_job_name with job_name.
Related
I want to create oracle job in specific date and time that runs only on that date and time once
and then dropped automatically.
The job should runs a procedure with 2 parameters also .
note: l_id I used this variable to add number beside procedure name to avoid any kind of duplication.
P94_DATE: the user will choose date and time and it will be stored in that variable.
here what I found so far but when I run this , it gives me 'statement proceed' but when I check if the job created successfully or not on 'sys.all_scheduler_jobs'
it doesn't exist.
dbms_scheduler.create_job (
job_name => 'eba_sb_reminder_s'||l_id,
job_type => 'STORED_PROCEDURE',
job_action => 'BEGIN send_Schedule_reminders(1,2); END;',
start_date => :P94_DATE, -- I need to assign time also !!
enabled => true,
comments => 'check if there is new reminders needs to be send in specific date and time'
);
end;
When job_type is set to STORE_PROCEDURE you must specify the name of the procedure in job_action.
The parameter start_date is of type DATE, which has a time as well in Oracle. You just need to set :p94_date with a correct value, containing a date and a time part.
If the procedure has parameters, you need to use DBMS_SCHEDULER.set_job_argument_value to specify a parameter-value.
Edit: Sample modified
Sample:
BEGIN
-- This needs to be configured just once.
DBMS_SCHEDULER.create_program(program_name => 'test_program',
program_type => 'STORED_PROCEDURE',
program_action => 'test',
number_of_arguments => 2,
enabled => FALSE,
comments => 'Comment');
DBMS_SCHEDULER.define_program_argument(program_name => 'test_program',
argument_name => 'p1',
argument_position => 1,
argument_type => 'NUMBER',
DEFAULT_VALUE => NULL);
DBMS_SCHEDULER.define_program_argument(program_name => 'test_program',
argument_name => 'p2',
argument_position => 2,
argument_type => 'NUMBER',
DEFAULT_VALUE => NULL);
DBMS_SCHEDULER.enable(name => 'test_program');
-- Create job
DBMS_SCHEDULER.create_job(
job_name => 'test_job',
program_name => 'test_program',
start_date => :p94_date,
enabled => FALSE,
comments => 'check if there is new reminders needs to be send in specific date and time');
-- Set Procedure Parameter
DBMS_SCHEDULER.set_job_argument_value(job_name => 'test_job', argument_position => 1, argument_value => 1);
DBMS_SCHEDULER.set_job_argument_value(job_name => 'test_job', argument_position => 2, argument_value => 2);
-- Enable job
DBMS_SCHEDULER.enable(name => 'test_job');
END;
"It's not working" is not found an any error message reference, and is totally devoid of actionable information.
That said:
You specify JOB_TYPE as STORED_PROCEDURE, so JOB_ACTION should be the name of a stored procedure. Instead you give it the code for an anonymous block.
JOB_NAME include a string concatenation that seems to try to include a variable. Where does that value come from and how do you think it is being populated when you execute this CREATE_JOB?
3)START_DATE also seems to try to include a variable/parameter. Again, Where does that value come from and how do you think it is being populated when you execute this CREATE_JOB?
dbms_scheduler.create_job (
job_name => 'eba_sb_reminder_s',
job_type => 'STORED_PROCEDURE',
job_action => 'send_Schedule_reminders(1,2)',
start_date => to_date('2021-03-22 13:00:00','yyyy-mm-dd hh24:mi:ss'),
enabled => true,
comments => 'check if there is new reminders needs to be send in specific date and time'
If this fails to meet your requirement (esp those attempts to include some sort of paramter, please explain in more detail what you are trying to achieve with them.
Create a resource, and limit jobs to 1
begin dbms_scheduler.create_resource(resource_name=>'SO_TEST_RESOURCE',units=>'1'); END;
While I can create a job, assign a resource, and even a priority, the subsequent jobs (assigned to the same resource and various priorities) that are queued, are run in random order not FIFO, and not in priority order. Looking for a way to force the next job queued (assigned to that same resource) to be the one that runs next.
DBMS_SCHEDULER.create_job (
job_name => 'SO_JOB1_TEST_RESOURCE',
job_type => 'PLSQL_BLOCK',
job_action => 'begin DBMS_SESSION.sleep(40); end;',
auto_drop => true,
start_date => systimestamp,
enabled => false);
DBMS_SCHEDULER.set_resource_constraint (
object_name => 'SO_JOB1_TEST_RESOURCE',
resource_name => 'SO_TEST_RESOURCE',
units => 1);
DBMS_SCHEDULER.SET_ATTRIBUTE(
NAME => 'SO_JOB1_TEST_RESOURCE',
ATTRIBUTE => 'job_priority',
VALUE =>1 );
DBMS_SCHEDULER.enable('SO_JOB1_TEST_RESOURCE');
.... adding more jobs 2, 3, 4 run in random order
Oracle DBMS_SCHEUDLER CHAINS is probably what you are looking for. You can create a chain first
BEGIN
DBMS_SCHEDULER.CREATE_CHAIN (
chain_name => 'my_chain1',
rule_set_name => NULL,
evaluation_interval => NULL,
comments => 'My first chain');
END;
/
... and then add each scheduled job into the chain as steps in the chain.
BEGIN
DBMS_SCHEDULER.DEFINE_CHAIN_STEP (
chain_name => 'my_chain1',
step_name => 'my_step1',
program_name => 'my_program1');
DBMS_SCHEDULER.DEFINE_CHAIN_STEP (
chain_name => 'my_chain1',
step_name => 'my_step2',
program_name => 'my_chain2');
END;
/
There is a lot more that can be done with job CHAINS, like checking status, implementing restart logic etc. Oracle Documentation will be good reference.
I am trying to run stored procedures in parallel - Oracle PL/SQL using dbms_scheduler but I am getting an error like an unknown job, I have also tried dbms_job, here I am getting an error- identifier dbms_jobs must be declared. Could someone please help me out?
Below are two approaches I have tried:
CREATE PACKAGE BODY pkg IS
CREATE PROCEDURE do_parallel_execution
IS
BEGIN
DBMS_SCHEDULER.RUN_JOB('pkg1.proc1', false);
DBMS_SCHEDULER.RUN_JOB('pkg1.proc2', false);
DBMS_SCHEDULER.RUN_JOB('pkg1.proc3', false);
END;
CREATE PACKAGE BODY pkg IS
CREATE PROCEDURE run_in_parallel
IS
l_jobno pls_integer;
BEGIN
dbms_job.submit(l_jobno, 'pkg1.proc1; end;' );
dbms_job.submit(l_jobno, 'pkg1.proc2; end;' );
-- dbms_job.submit(l_jobno, 'pkg1.proc3; end;' );
END;
where pkg1 has all 3 procedures defined in it.
Thank you!
To execute otherwise unrelated procedures in parallel, use a Scheduler Job Chain:
Create procedures:
create or replace package test as
procedure test1;
procedure test2;
procedure test3;
end test;
/
create or replace package body test as
procedure test1 is
begin
sys.dbms_session.sleep(5);
end test1;
procedure test2 is
begin
sys.dbms_session.sleep(5);
end test2;
procedure test3 is
begin
sys.dbms_session.sleep(5);
end test3;
end test;
/
Create Scheduler Programs for each procedure:
BEGIN
DBMS_SCHEDULER.create_program(
program_name => 'TEST1_PROGRAM',
program_action => 'TEST.TEST1',
program_type => 'STORED_PROCEDURE',
number_of_arguments => 0,
comments => NULL,
enabled => FALSE);
DBMS_SCHEDULER.ENABLE(name=>'TEST1_PROGRAM');
DBMS_SCHEDULER.create_program(
program_name => 'TEST2_PROGRAM',
program_action => 'TEST.TEST2',
program_type => 'STORED_PROCEDURE',
number_of_arguments => 0,
comments => NULL,
enabled => FALSE);
DBMS_SCHEDULER.ENABLE(name=>'TEST2_PROGRAM');
DBMS_SCHEDULER.create_program(
program_name => 'TEST3_PROGRAM',
program_action => 'TEST.TEST3',
program_type => 'STORED_PROCEDURE',
number_of_arguments => 0,
comments => NULL,
enabled => FALSE);
DBMS_SCHEDULER.ENABLE(name=>'TEST3_PROGRAM');
END;
/
Create the Scheduler Chain:
BEGIN
-- one step for each program
SYS.DBMS_SCHEDULER.DEFINE_CHAIN_STEP (
chain_name => 'TEST_CHAIN'
,step_name => 'CHAIN_STEP1'
,program_name => 'TEST1_PROGRAM');
SYS.DBMS_SCHEDULER.DEFINE_CHAIN_STEP (
chain_name => 'TEST_CHAIN'
,step_name => 'CHAIN_STEP2'
,program_name => 'TEST2_PROGRAM');
SYS.DBMS_SCHEDULER.DEFINE_CHAIN_STEP (
chain_name => 'TEST_CHAIN'
,step_name => 'CHAIN_STEP3'
,program_name => 'TEST3_PROGRAM');
-- one rule with condition "true" to start each step immediately
SYS.DBMS_SCHEDULER.DEFINE_CHAIN_RULE (
CHAIN_NAME => 'TEST_CHAIN',
rule_name => 'TEST_RULE1',
condition => 'TRUE',
action => 'START "CHAIN_STEP1"');
SYS.DBMS_SCHEDULER.DEFINE_CHAIN_RULE (
CHAIN_NAME => 'TEST_CHAIN',
rule_name => 'TEST_RULE2',
condition => 'TRUE',
action => 'START "CHAIN_STEP2"');
SYS.DBMS_SCHEDULER.DEFINE_CHAIN_RULE (
CHAIN_NAME => 'TEST_CHAIN',
rule_name => 'TEST_RULE3',
condition => 'TRUE',
action => 'START "CHAIN_STEP3"');
-- one rule to close out the chain after all steps are completed
SYS.DBMS_SCHEDULER.DEFINE_CHAIN_RULE (
chain_name => 'TEST_CHAIN',
rule_name => 'TEST_RULE4',
condition => 'CHAIN_STEP1 Completed AND CHAIN_STEP2 Completed AND CHAIN_STEP3 Completed',
action => 'END 0');
END;
/
The chain flow now looks like this (as depicted by SQL Developer):
Now create a Scheduler Job to run the chain:
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'TEST_JOB',
job_type => 'CHAIN',
job_action => 'TEST_CHAIN',
number_of_arguments => 0,
start_date => NULL,
repeat_interval => NULL,
end_date => NULL,
enabled => FALSE,
auto_drop => FALSE,
comments => '');
DBMS_SCHEDULER.SET_ATTRIBUTE(
name => 'TEST_JOB',
attribute => 'logging_level', value => DBMS_SCHEDULER.LOGGING_RUNS);
END;
/
And run the job:
BEGIN
DBMS_SCHEDULER.RUN_JOB(job_name => 'TEST_JOB', USE_CURRENT_SESSION => FALSE);
END;
/
Now look at the job run details for the job:
"LOG_ID" "LOG_DATE" "JOB_NAME" "JOB_SUBNAME" "STATUS" "ERROR#" "ACTUAL_START_DATE" "RUN_DURATION"
"1548" "14-JUN-20 12.15.46.744612000 AM -04:00" "TEST_JOB" "CHAIN_STEP3" "SUCCEEDED" "0" "14-JUN-20 12.15.41.708043000 AM AMERICA/NEW_YORK" "+00 00:00:05.000000"
"1544" "14-JUN-20 12.15.46.746544000 AM -04:00" "TEST_JOB" "CHAIN_STEP2" "SUCCEEDED" "0" "14-JUN-20 12.15.41.690404000 AM AMERICA/NEW_YORK" "+00 00:00:05.000000"
"1546" "14-JUN-20 12.15.46.748830000 AM -04:00" "TEST_JOB" "CHAIN_STEP1" "SUCCEEDED" "0" "14-JUN-20 12.15.41.690891000 AM AMERICA/NEW_YORK" "+00 00:00:05.000000"
"1550" "14-JUN-20 12.15.46.968592000 AM -04:00" "TEST_JOB" "" "SUCCEEDED" "0" "14-JUN-20 12.15.41.574115000 AM AMERICA/NEW_YORK" "+00 00:00:05.000000"
Note that:
The job starts at "12.15.41.574115000" (ACTUAL_START_DATE, Line 1550).
Each job step starts within a fraction of a second of the overall job start (as recorded in ACTUAL_START_DATE for each step in lines 1544, 1546, and 1548), and completes in the expected 5 seconds.
The overall job completes at "14-JUN-20 12.15.46.968592000" (LOG_DATE, Line 1550) with a total duration of 5 seconds to complete all three steps.
Note that rule processing may add a tiny bit of overhead to the total execution time for the chain.
The parallel processing can be achieved using the schedule job chain.
create schedule programs with the procedure function you want to run,
create a scheduler chain and define steps and rules,
create a job/scheduler job to call the scheduler chain
I have 7 Materialized Views that need to be refreshed on a schedule.
Five of them are data source independent and could be rebuilt asynchronously.
Two of them are dependent on some of the first five MViews and need to wait until those have been refreshed. These last two are independent of each other and could run asynchronously.
I originally asked this question here. My plan was to go the DBMS_JOB.SUBMIT route. It was explained to me that DBMS_JOB.SUBMIT is an Oracle 8-level approach to the problem and that I should look into using DBMS_SCHEDULER.
My question changed to: What is a better way to do synchronous and asynchronous MView refreshes in Oracle 11g?
I'd like to share the DBMS_SCHEDULER solution I used in case anyone is interested in a better approach to working with synchronous and asynchronous method calls in Oracle 11g.
TLDR:
Use DBMS_SCHEDULER.CREATE_PROGRAM to create named programs.
Use DBMS_SCHEDULER.CREATE_CHAIN to create a chain.
Use DBMS_SCHEDULER.DEFINE_CHAIN_STEP to define the steps in the chain to call the named programs created in #1.
Use DBMS_SCHEDULER.DEFINE_CHAIN_RULE to define when steps are called (this is where the synchronous and asynchronous calls are defined).
Use DBMS_SCHEDULER.CREATE_SCHEDULE to create a schedule to determine when the job created in #6 will run.
Use DBMS_SCHEDULER.CREATE_JOB to create a job that will run based on the schedule created in #5 to execute the chain created in #2.
Code:
-- First: Create the programs to refresh the MViews
BEGIN
-- Independent Programs
DBMS_SCHEDULER.CREATE_PROGRAM (
program_name => 'PROGRAM_REFRESH_MVIEW_I1',
program_action => 'BEGIN DBMS_MVIEW.REFRESH(list => ''IndependentMView1'', METHOD => ''C'') ; END;',
program_type => 'PLSQL_BLOCK',
number_of_arguments => 0,
comments => 'This Refreshes the IndependentMView1 MView.',
enabled => TRUE) ;
DBMS_SCHEDULER.CREATE_PROGRAM (
program_name => 'PROGRAM_REFRESH_MVIEW_I2',
program_action => 'BEGIN DBMS_MVIEW.REFRESH(list => ''IndependentMView2'', METHOD => ''C'') ; END;',
program_type => 'PLSQL_BLOCK',
number_of_arguments => 0,
comments => 'This Refreshes the IndependentMView2 MView.',
enabled => TRUE) ;
DBMS_SCHEDULER.CREATE_PROGRAM (
program_name => 'PROGRAM_REFRESH_MVIEW_I3',
program_action => 'BEGIN DBMS_MVIEW.REFRESH(list => ''IndependentMView3'', METHOD => ''C'') ; END;',
program_type => 'PLSQL_BLOCK',
number_of_arguments => 0,
comments => 'This Refreshes the IndependentMView3 MView.',
enabled => TRUE) ;
DBMS_SCHEDULER.CREATE_PROGRAM (
program_name => 'PROGRAM_REFRESH_MVIEW_I4',
program_action => 'BEGIN DBMS_MVIEW.REFRESH(list => ''IndependentMView4'', METHOD => ''C'') ; END;',
program_type => 'PLSQL_BLOCK',
number_of_arguments => 0,
comments => 'This Refreshes the IndependentMView4 MView.',
enabled => TRUE) ;
DBMS_SCHEDULER.CREATE_PROGRAM (
program_name => 'PROGRAM_REFRESH_MVIEW_I5',
program_action => 'BEGIN DBMS_MVIEW.REFRESH(list => ''IndependentMView5'', METHOD => ''C'') ; END;',
program_type => 'PLSQL_BLOCK',
number_of_arguments => 0,
comments => 'This Refreshes the IndependentMView5 MView.',
enabled => TRUE) ;
-- Dependent Programs
DBMS_SCHEDULER.CREATE_PROGRAM (
program_name => 'PROGRAM_REFRESH_MVIEW_D1',
program_action => 'BEGIN DBMS_MVIEW.REFRESH(list => ''DependentMView1'', METHOD => ''C'') ; END;',
program_type => 'PLSQL_BLOCK',
number_of_arguments => 0,
comments => 'This Refreshes the DependentMView1 MView.',
enabled => TRUE) ;
DBMS_SCHEDULER.CREATE_PROGRAM (
program_name => 'PROGRAM_REFRESH_MVIEW_D2',
program_action => 'BEGIN DBMS_MVIEW.REFRESH(list => ''DependentMView2'', METHOD => ''C'') ; END;',
program_type => 'PLSQL_BLOCK',
number_of_arguments => 0,
comments => 'This Refreshes the DependentMView2 MView.',
enabled => TRUE) ;
END;
/
-- Next: Create the chain to control the refresh steps
BEGIN
DBMS_SCHEDULER.CREATE_CHAIN (
chain_name => 'REFRESH_MVIEWS_CHAIN',
rule_set_name => NULL,
evaluation_interval => NULL,
comments => 'Refresh the Materialized Views in the correct order.') ;
END;
/
-- Next: Create the steps used to call the programs to refresh the MViews.
-- Note: Referenced programs must be enabled.
BEGIN
DBMS_SCHEDULER.DEFINE_CHAIN_STEP ('REFRESH_MVIEWS_CHAIN', 'stepI1', 'PROGRAM_REFRESH_MVIEW_I1') ;
DBMS_SCHEDULER.DEFINE_CHAIN_STEP ('REFRESH_MVIEWS_CHAIN', 'stepI2', 'PROGRAM_REFRESH_MVIEW_I2') ;
DBMS_SCHEDULER.DEFINE_CHAIN_STEP ('REFRESH_MVIEWS_CHAIN', 'stepI3', 'PROGRAM_REFRESH_MVIEW_I3') ;
DBMS_SCHEDULER.DEFINE_CHAIN_STEP ('REFRESH_MVIEWS_CHAIN', 'stepI4', 'PROGRAM_REFRESH_MVIEW_I4') ;
DBMS_SCHEDULER.DEFINE_CHAIN_STEP ('REFRESH_MVIEWS_CHAIN', 'stepI5', 'PROGRAM_REFRESH_MVIEW_I5') ;
-- stepD1 is dependent on IndependentMView1, IndependentMView2, IndependentMView3
DBMS_SCHEDULER.DEFINE_CHAIN_STEP ('REFRESH_MVIEWS_CHAIN', 'stepD1', 'PROGRAM_REFRESH_MVIEW_D1') ;
-- stepD2 is dependent on IndependentMView1, IndependentMView4
DBMS_SCHEDULER.DEFINE_CHAIN_STEP ('REFRESH_MVIEWS_CHAIN', 'stepD2', 'PROGRAM_REFRESH_MVIEW_D2') ;
END;
/
-- Next: Define rules for the chain. This is where we establish the
-- synchronous and asynchronous order of things. (i.e. where the magic happens)
BEGIN
-- First, start all independent steps asynchronously
DBMS_SCHEDULER.DEFINE_CHAIN_RULE ('REFRESH_MVIEWS_CHAIN', 'TRUE', 'START stepI1, stepI2, stepI3, stepI4, stepI5') ;
-- Next, start dependent steps as their related independent steps complete.
DBMS_SCHEDULER.DEFINE_CHAIN_RULE ('REFRESH_MVIEWS_CHAIN', 'stepI1 COMPLETED AND stepI2 COMPLETED AND stepI3 COMPLETED', 'START stepD1') ;
DBMS_SCHEDULER.DEFINE_CHAIN_RULE ('REFRESH_MVIEWS_CHAIN', 'stepI1 COMPLETED AND stepI4 COMPLETED', 'Start stepD2') ;
-- Last, define when the chain is complete.
-- In this case, we're done when both dependent steps and the one independent step that no other steps are dependent upon are all complete.
DBMS_SCHEDULER.DEFINE_CHAIN_RULE ('REFRESH_MVIEWS_CHAIN', 'stepI5 COMPLETED AND stepD1 COMPLETED AND stepD2 COMPLETED', 'END') ;
-- Enable the chain
DBMS_SCHEDULER.ENABLE ('REFRESH_MVIEWS_CHAIN') ;
END;
/
-- Next: create a schedule to run every 30 minutes at the top and bottom of every hour
BEGIN
DBMS_SCHEDULER.CREATE_SCHEDULE (
schedule_name => 'THIRTY_MINUTE_SCHEDULE',
repeat_interval => 'FREQ=MINUTELY;INTERVAL=30',
start_date => TO_TIMESTAMP_TZ ('2015-11-2 0:0:00.000000000 UTC', 'YYYY-MM-DD HH24:MI:SS.FF TZR'),
comments => 'Fires at the top and bottom of every hour') ;
END;
/
-- Lastly: Create a job to start the REFRESH_MVIEWS_CHAIN chain based on the THIRTY_MINUTE_SCHEDULE created above.
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'REFRESH_MVIEWS_JOB',
job_type => 'CHAIN',
job_action => 'REFRESH_MVIEWS_CHAIN',
schedule_name => 'TEN_TILL_TOP_BOTTOM_SCHEDULE',
number_of_arguments => 0,
enabled => FALSE,
auto_drop => FALSE,
comments => 'Refresh the Materialized Views');
DBMS_SCHEDULER.SET_ATTRIBUTE (
name => 'REFRESH_MVIEWS_JOB',
attribute => 'logging_level',
value => DBMS_SCHEDULER.LOGGING_OFF) ;
-- Enable the refresh job
DBMS_SCHEDULER.ENABLE (name => 'REFRESH_MVIEWS_JOB') ;
END;
/
Useful links along the way:
https://stackoverflow.com/a/16416525/384884
http://docs.oracle.com/cd/B28359_01/server.111/b28310/schedadmin006.htm#BAJHFHCD
http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_sched.htm#i1011194
http://docs.oracle.com/cd/B19306_01/server.102/b14231/scheduse.htm#CHDGAJAG
https://docs.oracle.com/cd/B28359_01/server.111/b28310/scheduse009.htm#CHDCFBHG
http://dba.fyicenter.com/faq/oracle/PL-SQL-Named-Program-Unit.html
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.