Pages

Sunday, May 15, 2016

Code Example for batch calling sqlplus

======================
General
======================
This is a simple code example, for batch script calling a general run_sql.bat file, which is calling a sqlplus.

======================
Files List
======================
refresh_updates.bat
run_sql.bat
refresh_updates.sql
REFRESH_UPDATES Procedure

======================
Files Content
======================

refresh_updates.bat
ECHO OFF
setlocal
cls

SET SQL_FILE=refresh_updates.sql

ECHO.
ECHO =============================================
ECHO refresh_updates.bat is starting
ECHO =============================================
ECHO.

SET DB_NAME=my_user/my_pass@orainst1
ECHO Running %SQL_FILE% on DB %DB_NAME%
call run_sql.bat %DB_NAME% %SQL_FILE%
ECHO Done
ECHO.


SET DB_NAME=my_user/my_pass@orainst2
ECHO Running %SQL_FILE% on DB %DB_NAME%
call run_sql.bat %DB_NAME% %SQL_FILE%
ECHO Done
ECHO.


ECHO.
ECHO =============================================
ECHO refresh_updates on has finished
ECHO =============================================

SET /p temp="Enter to Close this Window"

run_sql.bat
SET db_name=%1
SET sql_file_name=%2

sqlplus -s %db_name% @%sql_file_name% 

refresh_updates.sql
SET TERMOUT ON
SET SHOW OFF
SET VERIFY OFF 
SET HEAD ON
SET LINE 500
SET FEEDBACK ON
SET PAGES 500
SET TRIMS ON

BEGIN
  REFRESH_UPDATES;
END;
/
EXIT;

REFRESH_UPDATES Procedure
CREATE OR REPLACE PROCEDURE REFRESH_UPDATES IS
BEGIN
  DBMS_STATS.flush_database_monitoring_info;
END;

No comments:

Post a Comment