SQL Error Message


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SQL Error Message
# 1  
Old 07-12-2006
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.
# 2  
Old 07-12-2006
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.
# 3  
Old 07-12-2006
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
# 4  
Old 07-12-2006
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 08:24 AM..
# 5  
Old 07-12-2006
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get rid off Password expiry error message when connecting to sql in script?

I am connecting to sql databases through shell script. Databases that i am connecting will need password change every 60 days. This is according to our security policy and cannot be changed. But this is creating problem when connecting to Databases through shell script . To connect to oracle DB we... (2 Replies)
Discussion started by: pallvi_mahajan
2 Replies

2. UNIX for Dummies Questions & Answers

What does this error message mean?

I was reviewing logs and I got this error message in /var/log/messages: Did not receive identification string from (IP ADDRESS) What does it mean? (6 Replies)
Discussion started by: mojoman
6 Replies

3. Linux

error message

Hello I got this message error on my box with linux red hat 2887a374 WsServer E WSVR0009E: Error occurred during startup Do you know what does that mean ! Thanks in advance (1 Reply)
Discussion started by: lo-lp-kl
1 Replies

4. UNIX for Dummies Questions & Answers

Error Message

I keep getting an error message in a script im writing, this line is allways pointed out. if and this is the message i keep getting. line 32: [: 8: unary operator expected Whats wrong with it? Please Help. (5 Replies)
Discussion started by: chapmana
5 Replies

5. Shell Programming and Scripting

Error message

I am new to scripting. I am using the following script . BART.dat contains the string 'Y' . #!/bin/ksh cd /work/TCI/data_out file=`cat BART.dat` echo "$file" if ; then echo "true" fi When i am executing the above script i am getting the following error ./s.ksh: : not found ... (2 Replies)
Discussion started by: ammu
2 Replies

6. UNIX for Dummies Questions & Answers

getting last error message

Question for unix programmers - what function I need to used to get the exact error message when the library failed to load? Thanks (1 Reply)
Discussion started by: tttttt
1 Replies

7. Solaris

lp error message

Both of these messages are filling up the /var/adm/messages files on these two Sun boxes, goober and gomer. The print server is called gold. Jul 31 03:15:40 gold bsd-gw: request to ma28084.Solaris (unknown printer) from goober Jul 31 03:16:39 gold bsd-gw: request to ma28084.Solaris (unknown... (1 Reply)
Discussion started by: antalexi
1 Replies

8. UNIX for Advanced & Expert Users

Error message

I'm getting an error - symbol referencing errors. No output written to, etc Can anybody tell me why this is? (2 Replies)
Discussion started by: Dan Rooney
2 Replies

9. UNIX for Dummies Questions & Answers

Error Message

Hi everyone, Can anyone explain what the following error refers to...and perhaps a solution? vxfs: vx_nospace -/tmp file system full (8 block extent) Thanks, Uni (2 Replies)
Discussion started by: Uni
2 Replies
Login or Register to Ask a Question