Home » Infrastructure » Unix » Negative value returned from a SQL to a shell script
Negative value returned from a SQL to a shell script [message #155043] Wed, 11 January 2006 21:55 Go to next message
Anindya Banerjee
Messages: 5
Registered: December 2004
Junior Member
Hi gurus,

I am having a peculiar problem.

I have a SQL query (written in a file) to be executed from a shell script. The SQL query is a simple select count(*) query. It looks like:

my_sql.sql
---------------
WHENEVER OSERROR EXIT -2
WHENEVER SQLERROR EXIT -3
select count(*) from TBL1 where <where clause>;

The executing shell script looks like this:

execute_sql.sh
---------------------
sqlplus -s 'user/pass@host' <<EOF
@/home/adm/Temp/my_sql.sql
EOF
status=$?
echo $status
exit $status

Now I have deliberately put the TBL1 as a nonexistent table to check whether it's working for the SQLERROR part. What's happening is in the execute_sql.sh the status is being returned as (256 + (-3)) i.e. 253. For all the negative values it is returning after adding it with 256. But for +ve values it's returning perfectly.

I have to return some negative values as the count(*) could be 0 or more than 0, and only a negative value would trap an OS or SQL error.

It looks more like a shell scripting issue - but please let me know if someone has encountered similar problems and how to get rid of this.

Thanks in Advance,
- Anindya
Re: Negative value returned from a SQL to a shell script [message #155186 is a reply to message #155043] Thu, 12 January 2006 14:42 Go to previous messageGo to next message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
As far as I know, Unix return code is only in 1 byte (range 0-255), so overflow is responsible for the 253.

[Updated on: Thu, 12 January 2006 14:45]

Report message to a moderator

Re: Negative value returned from a SQL to a shell script [message #155364 is a reply to message #155186] Sun, 15 January 2006 02:27 Go to previous messageGo to next message
rleishman
Messages: 3728
Registered: October 2005
Location: Melbourne, Australia
Senior Member
I have shed so much blood trying to make bullet-proof Unix-calling-Oracle scripts. Quite simply, the mechanism for calling SQL*Plus from the OS and capturing any type of error is inadequate. SQL*Plus is an interactive tool, and should stay that way.

For running Oracle scripts from the OS, I now use Perl. Just download DBI and DBD::Oracle modules from the CPAN website, get your SA to install them, and I promise you will never use SQL*Plus in a script again.

_____________
Ross Leishman
Re: Negative value returned from a SQL to a shell script [message #155632 is a reply to message #155364] Tue, 17 January 2006 13:52 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:444389210579
Previous Topic: connect to database
Next Topic: Time taken to compress a file
Goto Forum:
  


Current Time: Sat Apr 20 00:43:24 CDT 2024