I have created below code, create_job is working fine but dbms_scheduler.enable is not running jobs automatically, however If I manually run created job i.e. begin REQUEST_PKG.CREATE_REQUEST('1234'); end; it runs successfully. Can someone please help me out here, to me it seems some compatibility/parameter passing issue in dbms_scheduler.enable.
DBMS_SCHEDULER.create_job
(job_name => job_name,
job_type => 'PLSQL_BLOCK',
job_action => 'begin REQUEST_PKG.CREATE_REQUEST('||seq_no|| '); end; ',
enabled => FALSE,
auto_drop => FALSE,
comments => seq_no
);
DBMS_SCHEDULER.ENABLE(job_name);
I am using oracle version 11.2.0.4.0.
Check your database initialization parameters. Specifically JOB_QUEUE_PROCESSES.
Documentation says :
If the value of JOB_QUEUE_PROCESSES is set to 0, then DBMS_JOB jobs and Oracle Scheduler jobs will not run on the instance.
Related
So what we trying to do is create a procedure that execute a batch file.
We been messing around with job instruction, but it seems like it doesn't work properly.
CREATE OR REPLACE PROCEDURE launch_bat AS
BEGIN
DBMS_SCHEDULER.create_job ('Export_Case_Job',
job_action => 'C:\WINDOWS\SYSTEM32\CMD.EXE',
number_of_arguments => 3,
job_type => 'executable',
enabled => FALSE);
DBMS_SCHEDULER.set_job_argument_value ('Export_Case_Job', 1, '/q');
DBMS_SCHEDULER.set_job_argument_value ('Export_Case_Job', 2, '/c');
DBMS_SCHEDULER.set_job_argument_value ('Export_Case_Job', 3, 'C:\scripts\helloFolder.bat');
DBMS_SCHEDULER.enable ('Export_Case_Job');
END;
/
call launch_bat;
It says that it compiled but we don't see any result in our folder. We also tried to give a file name in call.
We have Oracle 10.2 so we can't use exec xp_cmdshell.
Why procedure ? When we get new income data, we will execute a trigger with procedure that will go for a batch file, this batch file will create a certain information inside our folders as a test purporse.
The main focus is that oracle sql execute a batch file.
Batch content
ECHO OFF
mkdir C:\scripts\folder
Thanks in advance !
When I compare your example with the one from the docs https://docs.oracle.com/cd/E11882_01/server.112/e25494/scheduse.htm#CHDJHBAH:
BEGIN
DBMS_SCHEDULER.CREATE_JOB(
job_name => 'MKDIR_JOB',
job_type => 'EXECUTABLE',
number_of_arguments => 3,
job_action => '\windows\system32\cmd.exe',
auto_drop => FALSE,
credential_name => 'TESTCRED');
DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE('mkdir_job',1,'/c');
DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE('mkdir_job',2,'mkdir');
DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE('mkdir_job',3,'\temp\extjob_test_dir');
DBMS_SCHEDULER.ENABLE('MKDIR_JOB');
END;
/
EXECUTABLE vs. executable
\windows\system32\cmd.exe vs C:\WINDOWS\SYSTEM32\CMD.EXE
So I would expect that you have to write job_type in upper case. Probably job_action lower case, but I'm not sure there.
If the error is somewhere else you have to check:
*_SCHEDULER_JOB_LOG
*_SCHEDULER_JOB_RUN_DETAILS
Where I could find sufficiant information to migrate the example from the docs to linux with mkdir.
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;
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.
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;
I am a little new to programming, so any help is appreciated.
Find below the code of my stored proc to delete a table and also create a DBA job which will run on a hourly basis.
CREATE OR REPLACE procedure DELETE_My_TABLE(myschema varchar2) as
BEGIN
BEGIN
execute immediate 'delete from '||myschema||'.mytable where clause;';
END;
BEGIN
DBMS_SCHEDULER.create_program (
program_name => 'DELETE_My_TABLE',
program_type => 'STORED_PROCEDURE',
program_action => 'execute DELETE_My_TABLE(myschema)',
number_of_arguments => 1,
enabled => FALSE,
comments => 'Program to delete table using a stored procedure.');
DBMS_SCHEDULER.define_program_argument (
program_name => 'DELETE_My_TABLE',
argument_name => 'myschema',
argument_position => 1,
argument_type => 'VARCHAR2',
default_value => 'myschema');
DBMS_SCHEDULER.enable (name => 'DELETE_My_TABLE');
END;
BEGIN
DBMS_SCHEDULER.create_schedule (
schedule_name => 'DELETE_My_TABLE',
start_date => SYSTIMESTAMP,
repeat_interval => 'freq=hourly; byminute=0',
end_date => NULL,
comments => 'Hourly Job to purge SEARCH_TEMP_TABLE');
END;
END;
/
Issues:
ERROR at line 1:
ORA-00920: invalid relational operator
ORA-06512: at "MYSCHEMA.DELETE_My_TABLE", line 4
ORA-06512: at line 1
Will the logic (and syntax) work?
One issue I can see is that you need to take the semi-colon out of the EXECUTE IMMEDIATE string:
execute immediate 'delete from '||myschema||'.mytable where clause';
^^
Removed from here
thought I suspect this won't solve your immediate problem, which looks like it's your BEGIN ...END blocks.
For the Oracle Scheduler you normally create a program, once. Next you create a job that has the program as action. You can give that job a schedule like you specified in your code but you have to choose. Either you create a schedule and have the job use it, or you give the job it's own repeat interval.
I happen to know about a book ( Mastering Oracle Scheduler ) that I wrote that could be very helpful.