The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
unix-oracle kekanap Shell Programming and Scripting 2 02-11-2008 06:55 AM
unix for oracle ravi raj kumar UNIX for Dummies Questions & Answers 6 01-03-2007 02:19 AM
Unix + Oracle Khoomfire Shell Programming and Scripting 1 08-08-2005 02:39 AM
Oracle and Unix truma1 UNIX for Advanced & Expert Users 3 11-21-2001 03:08 PM
Oracle 9i on Unix gerald_agoi High Level Programming 2 09-17-2001 03:12 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-17-2006
Registered User
 

Join Date: Mar 2006
Posts: 35
Unix Oracle

Through a shell script ...

I am invoking sql plus..

Code is as follows...

echo " set feedback off verify off pagesize 0
select column from table " | sqlplus -s/@dbname | read var_col

Now if oracle throws an exception for above select statement ...then how can i catch it ? Please help..asap

Thanks...
Reply With Quote
Forum Sponsor
  #2  
Old 03-17-2006
Registered User
 

Join Date: Mar 2006
Posts: 143
I would assume that the sqlplus utility would return with non-zero return code
which you could catch either through $? or by direct shell logic.
However, I would rather rely on something like Perl's DBI (or DBD::Oracle below)
for anything in Oracle/Unix interaction.
Reply With Quote
  #3  
Old 03-20-2006
Registered User
 

Join Date: Jul 2005
Location: Mt. Prospect, Illinois
Posts: 32
UNIX Oracle

You could continue the script with an if statement. For example, if the exception is: except, then you could insert an "if" statement in the script for
handling it:

if [[ $except -ne or -eq for not equal or for equal or Whatever option ]]
then
list of operations to perform
or
else
fi

Mr-synapse
Reply With Quote
  #4  
Old 03-20-2006
Registered User
 

Join Date: Jan 2005
Posts: 682
There are many ways to accomplish this.
Code:
echo "WHENEVER SQLERROR EXIT 1
 set feedback off verify off pagesize 0
select column from table " | sqlplus -s/@dbname 
if [[ $? -ne 0 ]] ; then
    do something...
fi
Or you can do something like this:
Code:
{
echo "WHENEVER SQLERROR EXIT 1
set feedback off verify off pagesize 0
select column from table; " | sqlplus -s/@dbname
} | while IFS=$(echo '\012\001') read LINE ; do
    case ${LINE} in
       ORA-*|SP2-*) do some stuff based on Oracle error ;;
       *) echo ${LINE} ;;
    esac
done
Reply With Quote
  #5  
Old 03-24-2006
Registered User
 

Join Date: Mar 2006
Posts: 35
Quote:
Originally Posted by tmarikle
There are many ways to accomplish this.
Code:
echo "WHENEVER SQLERROR EXIT 1
 set feedback off verify off pagesize 0
select column from table " | sqlplus -s/@dbname 
if [[ $? -ne 0 ]] ; then
    do something...
fi
Or you can do something like this:
Code:
{
echo "WHENEVER SQLERROR EXIT 1
set feedback off verify off pagesize 0
select column from table; " | sqlplus -s/@dbname
} | while IFS=$(echo '\012\001') read LINE ; do
    case ${LINE} in
       ORA-*|SP2-*) do some stuff based on Oracle error ;;
       *) echo ${LINE} ;;
    esac
done

Hi ,

can u please interpret from while statement.
I am not getting IFS=$(echo '\012\001') read LINE ?

I tried it but its not giving the proper error msg...

Thanks...
Reply With Quote
  #6  
Old 03-24-2006
Registered User
 

Join Date: Jan 2005
Posts: 682
I want to read whole lines back from Oracle queries so I am setting the field separator to newlines only for the WHILE..read loop. Otherwise, the read would read each word rather than the whole line. I use echo '\012' (\012 = newline) because I don't like to break up lines like this IFS='
'. I add \001 because if I use \012 by itself, it doesn't seem to stick for me.
Reply With Quote
  #7  
Old 03-27-2006
Registered User
 

Join Date: Mar 2006
Posts: 35
Please help

Quote:
Originally Posted by tmarikle
I want to read whole lines back from Oracle queries so I am setting the field separator to newlines only for the WHILE..read loop. Otherwise, the read would read each word rather than the whole line. I use echo '\012' (\012 = newline) because I don't like to break up lines like this IFS='
'. I add \001 because if I use \012 by itself, it doesn't seem to stick for me.

My code is as follows

line_no=10
pro=TEST
{
echo "WHENEVER SQLERROR EXIT 1
set feedback off verify off pagesize 0
select x from tp_mquote where ct1=0; " | sqlplus -s/ /
} | while IFS=$(echo '\012\001') read LINE;
do
case ${LINE} in
ORA-*|SP2-*) echo "Hido some stuff based on Oracle error" ;;
*) echo ${LINE} ;;
esac
done
echo $?
if [ $? -ne 0 ]; then
global_proc $line_no $proc_name
else
echo Success
fi

------Now their is error in sql statement as the column in WHERE clause does not exist in that table...-------------

But before echoing that error it echoes
sql statement and then all FILE NAMES in my pwd
and after that the actual error..

1. How can i avoid those FILE name..
2. I want to write this error to file a.out.

Please help.
Thanks & Regards,
Dhananjay
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:29 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0