Hosting Service

30 May 2018 | MAK Azad

How to run an oracle job from windows batch file

Category : Oracle | Tag : windows batch scripting | Oracle Job |

Usually a job is run by the scheduler automatically after a certain period which is specified in the job. But some time you may need to run it manually by the end user. In this situation we can run it from windows batch file (.bat) file.

Here is an example of .bat file(runjob.bat) which will run a oracle job and write the success/error message in a text file(runjoblog.txt). Runjob.bat file:

Rem Azad May 2018
sqlplus rmwlapp/rmwlapp@rmwlappdb @E:\Azad\runprocedure.sql

In this file first line ‘Rem Azad May 2018’ is a commented line which will not be executed

Second line ‘@echo’ will show the content of this file on cmd screen. You can use ‘@echo off’ if you wish not to show the content on screen.

In Third line there is three part First part ‘sqlplus’ will invoke oracle sqlplus editor Second part ‘user/password@tns_name’ is connect string to database. And third part ‘@E:\Azad\runjob.sql’ will run a sql file in which we will write our sql or pl/sql code.

runjob.sql file:

set pagesize 0
spool on
spool E:/Azad/runjoblog.txt

   DBMS_SCHEDULER.run_job ( job_name => 'ATT_RUN_SCHEDULE', use_current_session => FALSE);

/ quit
spool off

Here: 'spool E:/Azad/runjoblog.txt' Line will write success/error message in runjoblog.txt file

DBMS_SCHEDULER.run_job ( job_name => 'ATT_RUN_SCHEDULE', use_current_session => FALSE);

This PL/SQL code will run the job which name is 'ATT_RUN_SCHEDULE'

All post under category Oracle

1. How to convert number into word/text with PL/SQL
2. An Overview and Clear Understanding of Oracle REF CURSOR
3. How to query/fetch data of MS Access DB from an Oracle DB?
4. How to install Apex5 with Oracle REST Data Services in windows
5. How to Restore Deleted Rows in Oracle | Data Recovery
6. How to run an oracle job from windows batch file
7. How to convert | export oracle matrix report into M.S Excel file, oracle 11g