Exit when sql script give error


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Exit when sql script give error
# 1  
Old 01-07-2016
Exit when sql script give error

Hi Guys,

I am calling a SQL script which runs under while loop, i need to exit the while loop if i get error in sql script which is called
Code:
while [i -le 10] 
do
sqlplus -s user/pass@db @test.sql id$i
done

test.sql
whenever sqlerror exit;
alter table t1 add &1 number;

I need to come out of while loop if i find error in any of the calling test.sql script with error message stating test.sql failed for 1st loop hence exiting loop
# 2  
Old 01-07-2016
With some corrections - mind your spaces around [[ and [ :
try:

Code:
status=0
while [[ $i -le 10 && $status -eq 0 ]] 
do
sqlplus -s user/pass@db <<-EOF
@test.sql id${i}
EOF
status=$?
if [ $status -ne 0 ] ; then
   echo "script failed on $i"
fi
done

test.sql code:
Code:
# test.sql
whenever sqlerror exit failure;
alter table t1 add &1 number;
exit 0

# 3  
Old 01-08-2016
Thanks,

is there a way exit the loop with error message if there is any DB connection issue for eg

Code:
sqlplus -s db/user@db

ORA-12154: TNS:could not resolve the connect identifier specified

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script with sql script error

Hi All when I execute from psql prompt, I get the result, when I try to automate using a shell script, the query is not working # `/usr/bin/psql -U postgres -d coba1 -c "select name from users where "Date" > current_date - 30;"` ERROR: column "Date" does not exist LINE 1: select... (2 Replies)
Discussion started by: srilinux09
2 Replies

2. Shell Programming and Scripting

Getting detailed error from sql script

Hello, I have a main.sql file which runs around 5-6 .sql files and each .sql file is spooling it in separate text file. In my shell script I am appending main.sql to one of my log file but I am not able to get detailed error if anything fails from those 5-6 .sql files. Those errors are... (1 Reply)
Discussion started by: sp92
1 Replies

3. Shell Programming and Scripting

How to catch sql error in script?

Hi Gurus, I have a script which send sql query to oracle db and return value to my script. dummy code like below: sqlplus -s user/${PASSWD}@${ORACLE_SID} @${DIR}/query.sql > outputfile using above code, when query has error, it send error to same out put file and exit code is 0, is... (6 Replies)
Discussion started by: ken6503
6 Replies

4. Shell Programming and Scripting

How to exit a script with error ?

Hi, I have a script ABC which calls another script XYZ. Function of XYZ is to ftp a file from one server to another. code for ABC: #!/bin/ksh PATH=/usr/bin home/user/xyz "$@" exit $? ~ code for xyz: #!/bin/ksh HOSTNAME=$1 SRCNAME=$2 DSTNAME=$3 (4 Replies)
Discussion started by: Salil Gupta
4 Replies

5. UNIX for Advanced & Expert Users

How to Make Sql Plus Exit with an Error Code

Dear all, How to make sqlplus command to exit with an apt error code in bash script, It always returns 0 for me. Thanks (9 Replies)
Discussion started by: vetrivendhan
9 Replies

6. Shell Programming and Scripting

How to grep sql error in shell script and exit the script?

I need help in the following script. I want to grep the sql errors insert into the error table and exit the shell script if there is any error, otherwise keep running the scripts. Here is my script #!/bin/csh -f source .orapass set user = $USER set pass = $PASS cd /opt/data/scripts echo... (2 Replies)
Discussion started by: allinshell99
2 Replies

7. Shell Programming and Scripting

source a property file in script give error

I have sourced a property file in my script like this to load some variables in the script Then i am able to echo all the property file values inside script but the script is not able to recognize other unix commands #!/bin/bash . build.properties mkdir build i am getting error ... (3 Replies)
Discussion started by: codeman007
3 Replies

8. Shell Programming and Scripting

error connecting sql through a shell script

Hi I am getting this error while connecting to sql through a shell script, whereas i am able to connect to sql directly. It was working properly earlier, no clue why i am getting this. Please find the log below: FTP to <IP> completed Wed Apr 30 11:42:01 BST 2008 Program ended. Wed Apr 30... (1 Reply)
Discussion started by: nehak
1 Replies

9. UNIX for Dummies Questions & Answers

connecting to a database through a script...if not give an error msg

Hello , i have a problem in writing the shell script.. i have a script already written n just need to make a change in which when the script is not able to connect to the database ..it should print an error msg on the screen. I have already seen previous posts on how to connect to the... (3 Replies)
Discussion started by: sommer_queen
3 Replies

10. Shell Programming and Scripting

Error while trying to fire a PL/SQL thro Unix Script

hi , I tried running a PL/SQL script through unix shell script. But am getting the following error. "Message file sp1<lang>.msb not found Error 6 initializing SQL*Plus " Kindly suggest. Regards, Samit (5 Replies)
Discussion started by: dharmesht
5 Replies
Login or Register to Ask a Question