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
Error Message chapmana UNIX for Dummies Questions & Answers 5 11-29-2006 07:41 AM
Error Message RDM00 UNIX for Dummies Questions & Answers 2 10-06-2006 03:43 PM
Error message ghuber UNIX for Advanced & Expert Users 1 11-14-2005 02:04 AM
error message vnc Castelior UNIX for Advanced & Expert Users 3 10-21-2004 01:50 AM
error message alisev UNIX for Dummies Questions & Answers 3 01-08-2002 01:01 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-12-2006
Registered User
 

Join Date: Jul 2006
Posts: 12
SQL Error Message

Hi,

I have a script that will call a .sql file in unix.
My question is, incase the .sql file encountered an error on execution (e.g. 'ORA-00942: table or view does not exist') is it possible to get that error back to the script that call the .sql file?

Please give me an example.

Thanks.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-12-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,199
If you want that the execution of your script ends with an error status at the first error encountered, add the following code to your SQL script :

Code:
WHENEVER SQLERROR EXIT FAILURE
WHENEVER OSERROR  EXIT FAILURE
Jean-Pierre.
Reply With Quote
  #3 (permalink)  
Old 07-12-2006
Dhruva's Avatar
Registered User
 

Join Date: Mar 2006
Location: India
Posts: 241
This is not a full fledged script but will give you insight how to catch error.



Z=`sqlplus -s user/password@host <<eof
set serveroutput on;
declare
v_message varchar2(1000);
v_value number;
begin
select column into v_value from tablename where rownum<2;
EXCEPTION
WHEN OTHERS THEN
v_message := SQLERRM;
dbms_output.put_line(v_message);
END;
/
EXIT;
eof`
v_message=`echo "$Z" | grep "ORA-"`
echo $v_message
Reply With Quote
  #4 (permalink)  
Old 07-12-2006
Registered User
 

Join Date: Jul 2006
Posts: 12
Thanks for the reply.

What this code do?

v_message=`echo "$Z" | grep "ORA-"`
echo $v_message

Is it possible to assign value to a unix environment variable in .sql file?

Last edited by kakashi_jet; 07-12-2006 at 04:24 AM.
Reply With Quote
  #5 (permalink)  
Old 07-12-2006
Dhruva's Avatar
Registered User
 

Join Date: Mar 2006
Location: India
Posts: 241
v_message=`echo "$Z" | grep "ORA-"`
echo $v_message

Variable Z contains the ouput of sqlplus session.from that output we are searching for "ORA-" string,Which is prefix to oracle error.The lines found with ORA- String are kept in another variable v_message.Second line is printing that oracle error message.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:48 AM.


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

Content Relevant URLs by vBSEO 3.2.0