I have a .bat file which runs two SQL files and moves files around. I need to have some error handling in this .bat file. I want it to take the error generated in sql and pass it into AutoSys I was provided with this code:
#!/bin/sh
. $HOME/.bash_profile
sqlplus -s $AUTOSYS_DB_USER/$AUTOSYS_DB_PASSWD <<!
WHENEVER OSERROR EXIT 999;
WHENEVER SQLERROR EXIT SQL.SQLCODE;
alter session set nls_date_format='DD/MM/YYYY';
execute P_LOST_APPROVALS;
!
exit_code=$?
if [ $exit_code != 0 ]; then
echo "Error calling sqlplus, return code = " $exit_code
exit $exit_code
fi
exit 0
However, I need it to run in .bat file and not Linux?
I currently have:
echo exit | sqlplus -s %CONNECT% @Code.sql
IF %ERRORLEVEL% NEQ 0 (
echo Unsuccessful
goto @ERROR_HANDLING_SQL
)
Full .bat file:
@echo off
call config.bat
SET CONNECT=%var1%/%var2%@avpr.world
Pushd Location
Set SCRIPTPATH=Location
Set RESULTPATH=Location
echo exit | sqlplus -s %CONNECT% @Code.sql
IF %ERRORLEVEL% NEQ 0 (
echo Unsuccessful
goto @ERROR_HANDLING_SQL
)
echo exit | sqlplus -s %CONNECT% @createTXT.sql > File%date:~0,2%%date:~3,2%%date:~6,4%.txt
IF %ERRORLEVEL% NEQ 0 (
echo Unsuccessful
goto @ERROR_HANDLING_SQL
)
move "File%date:~0,2%%date:~3,2%%date:~6,4%.txt" %RESULTPATH%
echo exit | sqlplus -s %CONNECT% @dropTable.sql
IF %ERRORLEVEL% NEQ 0 (
echo Unsuccessful
goto @ERROR_HANDLING_SQL
)
: ERROR_HANDLING_SQL
<echo -1>
pause
Exit