Create Scheduled Job in Oracle to Execute Batch File

Tags: Scheduled, Job, Oracle, Execute, Batch, File, .bat

from AskTime:

I just did this on my machine with no problems -

C:\>type c:\temp\demo.cmd
@echo off
echo Hello > c:\temp\demo.out
dir c:\temp >> c:\temp\demo.out
exit

SQL> declare
  2    vname varchar(20) := 'DEMOJOB';
  3  BEGIN
  4    begin dbms_scheduler.drop_job (vname); exception when others then null; end ;
  5    dbms_scheduler.create_job(
  6      job_name => vname,
  7      job_type => 'EXECUTABLE',
  8      job_action => 'C:\Windows\System32\cmd.exe',
  9      number_of_arguments => 2,
 10      enabled => FALSE);
 11    dbms_scheduler.set_job_argument_value( job_name => vname, argument_position => 1, argument_value => '/c');
 12    dbms_scheduler.set_job_argument_value( job_name => vname, argument_position => 2, argument_value => 'c:\temp\demo.cmd');
 13    dbms_scheduler.enable( vname);
 14
 15  END;
 16  /

PL/SQL procedure successfully completed.



So perhaps use a CMD file rather than a BAT file.

Also, on Windows, check the the "Oracle JobScheduler" service is running. If that isnt running you'll get errors in your alert log, eg, I disabled my service and I see this:

2017-09-15T08:46:30.042872+08:00
Errors in file C:\ORACLE\diag\rdbms\db122\db122\trace\db122_j000_10140.trc:
ORA-12012: error on auto execute of job "MCDONAC"."DEMOJOB"
ORA-27370: job slave failed to launch a job of type EXECUTABLE
ORA-27300: OS system dependent operation:accessing job scheduler service failed with status: 2
ORA-27301: OS failure message: The system cannot find the file specified.
ORA-27302: failure occurred at: sjsec 5
ORA-27303: additional information: The system cannot find the file specified.

No Comments

You must log on to comment.