I have a script which send sql query to oracle db and return value to my script.
dummy code like below:
using above code, when query has error, it send error to same out put file and exit code is 0, is there any way to make the sqlplus exit code other than 0 if the query contains any error?
So not quite.
has something to do with 1476 being modded down by 256 (or something - i'll let somebody more knowledgeable comment on that)
My reply was geared towards providing the OP with an exit code other than zero from sqlplus in case of failure...because the default behavior of sqlplus is to return zero to its environment irrespective of what goes on inside of it. Also the sqlcode returned to the shell will always be truncated to stay within the shell limits <0-255>. In the example you provided the sqlcode for the ORA error is 1476 which is not mod'd down...but is truncated bitwise leaving only the 8 least significant bits. As 1476 is 0x000005C4 and its 8 LS bits are 0xC4 giving a decimal value of 196. However the exact sqlcode will still be be dumped to the logfile and can be extracted from there...
Quote:
Originally Posted by Ditto
I've had most success by just grepping the output file for an ORA- error code (or SP2, etc.)
and then you have an error if either:
[ $ERR -ne 0 ] || [ $ERRC -ne 0 ]
Yes it can be re-directed to the logfile and viewed in there...
Quote:
Originally Posted by Ditto
Also, to the OP: Ken6503: you should be careful with this.
Your password will be visible to anyone on the same server, via "ps -ef" command.
If you're using an automated script, you really should consider externally defined ids, and then just use:
My reply was geared towards providing the OP with an exit code other than zero from sqlplus in case of failure...because the default behavior of sqlplus is to return zero to its environment irrespective of what goes on inside of it.
Understood, however, the only issue I was trying point out was that because of that bit-wise fun, depending on the error code sent back, it *could* come back as 0, despite throwing an error.
(ie if Oracle throws ORA-00256, even with the WHENEVER logic there, it'll pass error code 256 back to unix, get mashed to 0, and say "oh hey, everything's fine"
So unfortunately, it's hard to rely on that. Just have to be careful.
Understood, however, the only issue I was trying point out was that because of that bit-wise fun, depending on the error code sent back, it *could* come back as 0, despite throwing an error.
Yes that is correct since error codes with all zeros in their LS byte would be interpreted as success because $? evaluates to zero...
Quote:
Originally Posted by Ditto
(ie if Oracle throws ORA-00256, even with the WHENEVER logic there, it'll pass error code 256 back to unix, get mashed to 0, and say "oh hey, everything's fine"
So unfortunately, it's hard to rely on that. Just have to be careful.
ORA-00256 is 0x100 with its least significant byte being zero meaning that $? is zero and for all scenarios where the lsb is zero...perhaps the only workaround is to have a hard-coded value i.e. whenever sqlerror exit 1and redirect all stdout/stderr to a logfile and after the sqlplus sessions ends...peek inside to see the exact error that caused the abend or wait until the shell is fixed so that no bits are truncated...
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)
Hi Experts,
Problem summary :
I am facing the below problem on huge files when the disk is getting full on the half way through the execution.
If the disk was already full , the commands fail & everything is fine.
Sample Code :
head_rec_data_file=`head -1 sample_file.txt`
cat... (9 Replies)
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)
We have script running to SFTP some file to the remote server. The problem is the SFTP transfer returns an exit code of 0 even if there is permission error during file transfer, connection refuse (like when sftp server is down), thus, returning the status of the script as success.
I was thinking... (3 Replies)
I have some unstable mistake in my program and out-of-idea how to catch it.
I am looking for advice with a way to work it out!
I have in a pretty complicated program (but one source file) set of int-counters - 15, if exactly.
Lately, on final printout I have inpossible value (I am... (3 Replies)
I tried searching the forum for similar posts but its closed now.
Would appreciate any help on this.
I am trying to capture return value from a select query into a variable.
DB is Oracle
I am able to spool it to a file but I donot intend to use it.
Here is my script that does not work ;)
I... (27 Replies)
Hi Everyone,
How to use catch, try and final in bash script?
what is (SQLException e) and (IOException e), who to conver this 2 function to bash script?
Thank you (8 Replies)
Hi all
Im trying to call a PL SQl block from a ksh file like this :
sqlplus -s $DB_USERID/$DB_PASSWD@$DB_NAME<<eof
whenever SQLERROR exit 1
var varError VARCHAR2(200);
exec ODAS_BATCH_JOBS_RETRIEVE.retrieve_user_info(:varError);
eof
If there is a error then varError will return a... (1 Reply)
Hello,
I need some help from the experts on PL/SQL and Shell scripting. I need a shell script that runs a PL/SQL procedure and gets the values returned from the PL/SQL procedure into the shell variables. The PL/SQL procedure returns multiple values.
I was able to assign a single return value... (1 Reply)
I'm having a question about for loops. (bash)
I have the following for example:
for file in `ls *.txt`
do
read file ...
done
Now when there is a file present there is no problem, now when there is no file present I get the following output in my standard mail box : "No such... (4 Replies)