Stop execution of batch file on error for sqlplus in oracle

Rajubhai

I am having 4 files named test.bat which contains

@echo off
C:\oraclexe\app\oracle\product\10.2.0\server\BIN\sqlplus -s -l user/pass@localhost @E:\Oracle_Files\query.sql>E:\Oracle_Files\error.txt;
C:\oraclexe\app\oracle\product\10.2.0\server\BIN\sqlplus -s -l user/pass@localhost @E:\Oracle_Files\query1.sql>E:\Oracle_Files\error.txt

Now query.sql contains

WHENEVER SQLERROR EXIT SQL.SQLCODE
insert into mytable12 values('d');
exit;

And query1.sql contains

WHENEVER SQLERROR EXIT SQL.SQLCODE
begin
insert into mytable1 values('d2');
end;
exit; 

Now the problem is REAL TABLE NAME is mytable1,so here problem is I want to stop execution of batch file as soon as error came below scripts on error should not get executed, and also on error errorlog.txt file content gets replaced with "1 row updated" that means my previous error message are getting overwrite, how can I stop this ?

In short there are 2 issues

  • how to stop further execution of scripts on error in particular 1 script file.
  • How to prevent from overwriting of logs in log file
Brad Bruce

You need to check the errorlevel after each call to SQL*Plus

@echo off
C:\oraclexe\app\oracle\product\10.2.0\server\BIN\sqlplus -s -l user/pass@localhost @E:\Oracle_Files\query.sql>E:\Oracle_Files\error.txt;
if errorlevel 1 (
  goto error
)
C:\oraclexe\app\oracle\product\10.2.0\server\BIN\sqlplus -s -l user/pass@localhost @E:\Oracle_Files\query1.sql>>E:\Oracle_Files\error.txt
    if errorlevel 1 (
      goto error
    )
:: no error, skip error message
    goto end
    :error
      echo error occurred - check log file
    :end

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to handle sqlplus error in batch file

From Dev

Windows Batch file execution error

From Dev

error running `sqlplus` as user `oracle`

From Dev

sqlplus hangs after being called from a batch file, without throwing up error message

From Dev

Oracle sqlplus 12c error with queries

From Dev

Stop a "completly hidden batch file"

From Dev

batch - How to stop confirmation of deletion of file in batch

From Dev

Convert .sh file to a batch file for execution in windows

From Dev

Error in stored procedure execution in oracle

From Dev

How to make Oracle sqlplus spool query results to a file?

From Dev

Calling Gradle from .bat causes batch execution to stop

From Dev

Stop code execution on error (C++)

From Dev

Bash - prevent script to stop execution on error

From Dev

Stop code execution on error (C++)

From Dev

Composer exit batch file after finish execution

From Dev

close batch file after execution in java

From Dev

C# batch file execution never exits

From Dev

Fire batch (.bat) file execution and continue

From Dev

Getting input data after execution of batch file

From Dev

Batch file execution issue (CALL does NOT work)

From Dev

Exit WLST and continue execution of batch file

From Dev

Standalone Jar Execution From Batch File

From Dev

cmd command execution using batch file

From Dev

Batch script execution error "%%G was not expected"

From Dev

Batch File Input Error?

From Dev

batch file, for and findstr error

From Dev

BATCH file showing error

From Dev

Batch file - IF Error

From Dev

Oracle Script File Execution in *.bat file not completing