473,414 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

How to know in a unix script if oracle procedure executed or failed?

Hi,

I am writing my first script to execute a Oracle procedure through a
unix script. Could you tell me how do I do error handling here? How do
I know in my script if the procedure executed successfully or failed?
Thanks

#!/usr/bin/ksh
sqlplus user/password@name <<EOC
set time on
set echo on
select sysdate from dual
;
spool procedureName.log
exec procedureName
spool off
exit
EOC
Jul 19 '05 #1
5 24052
On 10 Dec 2003 13:18:38 -0800, c_******@hotmail.com (vishal) wrote:
Hi,

I am writing my first script to execute a Oracle procedure through a
unix script. Could you tell me how do I do error handling here? How do
I know in my script if the procedure executed successfully or failed?
Thanks

#!/usr/bin/ksh
sqlplus user/password@name <<EOC
set time on
set echo on
select sysdate from dual
;
spool procedureName.log
exec procedureName
spool off
exit
EOC


In the sql script include
whenever sqlerror exit failure
and the script will exit with a non-zero status.
If this is not sufficient look up whenever sqlerror and whenever
oserror on http://tahiti.oracle.com
--
Sybrand Bakker, Senior Oracle DBA
Jul 19 '05 #2
Hello,

you can use some other solution:

#!/usr/bin/ksh
sqlplus user/password@name <<EOC>/tmp/log/log_file_unix_shell.log
set time on
set echo on
select sysdate from dual
;
spool procedureName.log
exec procedureName
spool off
exit
EOC

you find the output of your user(SQL)-session in the
/tmp/log/log_file_unix_shell.log-File.

best regards
thorsten häs

On Wed, 10 Dec 2003 23:49:22 +0100, Sybrand Bakker
<go********@sybrandb.demon.nl> wrote:
On 10 Dec 2003 13:18:38 -0800, c_******@hotmail.com (vishal) wrote:
Hi,

I am writing my first script to execute a Oracle procedure through a
unix script. Could you tell me how do I do error handling here? How do
I know in my script if the procedure executed successfully or failed?
Thanks

#!/usr/bin/ksh
sqlplus user/password@name <<EOC
set time on
set echo on
select sysdate from dual
;
spool procedureName.log
exec procedureName
spool off
exit
EOC


In the sql script include
whenever sqlerror exit failure
and the script will exit with a non-zero status.
If this is not sufficient look up whenever sqlerror and whenever
oserror on http://tahiti.oracle.com
--
Sybrand Bakker, Senior Oracle DBA


--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jul 19 '05 #3
On Thu, 11 Dec 2003 19:28:33 +0100, Thorsten Häs
<ei*********@t-online.de> wrote:
Hello,

you can use some other solution:

#!/usr/bin/ksh
sqlplus user/password@name <<EOC>/tmp/log/log_file_unix_shell.log
set time on
set echo on
select sysdate from dual
;
spool procedureName.log
exec procedureName
spool off
exit
EOC


you find the output of your user(SQL)-session in the
/tmp/log/log_file_unix_shell.log-File.

best regards
thorsten häs

He wants to know *in the script* whether his procedure succeeded., not
by looking at log files. Your solution doesn't work, so why contradict
me with a non-working solution where my solution does work?
--
Sybrand Bakker, Senior Oracle DBA
Jul 19 '05 #4
Sybrand Bakker <go********@sybrandb.demon.nl> wrote
He wants to know *in the script* whether his procedure succeeded., not
by looking at log files. Your solution doesn't work, so why contradict
me with a non-working solution where my solution does work?


Exactly.

In addition you can also declare a bind variable in SQL*Plus and set
it in anon PL/SQL blocks in the script (kind of like a process status
code). Then terminate the script with the EXIT command using the bind
variable as parameter.

Also, the OP should note that the exitcode in Unix is a byte, while
the actual exitcode in SQL*Plus (especially when using SQL%SQLCODE to
return ORA error numbers) is two bytes. Thus you cannot determine the
actual Oracle error code in the Unix script by using the exitcode (in
that case you will need to grep the spoolfile).

--
Billy
Jul 19 '05 #5
vishal <c_******@hotmail.com> wrote:

: I am writing my first script to execute a Oracle procedure through a
: unix script. Could you tell me how do I do error handling here? How do
: I know in my script if the procedure executed successfully or failed?
: Thanks

What I do is run the script with the output piped to a log file and within
the script itself, test for errors...
Within the stored procedure itself, there's a bunch of EXCEPTION handling
clauses with more specific error messages.

$HOME/bin/qs "execute load_table('X')"
echo "load_table has executed"

if [ $? -ne 0 ]
then
echo "An error has occurred"
exit
fi

err=`grep 'ORA-' $HOME/logfile|wc -1
if [ $err -ne 0 ]
then
echo "An ORACLE error has occurred"
exit
fi

Hope this helps!
Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Holly | last post by:
I copied this code that works to connect into Unix. I am looking for a way to get it to work with a secure Unix box. Anyone have any insights on how to do this? I am trying to build an sftp...
1
by: ancy | last post by:
hi all I am calling a procedure within script.Even if the prcoedure is not executed successfully. In log file it is recorded as procedure successfully executed .How to capture errors in log file ...
4
by: istruttorenuoto | last post by:
hi to everbody i need to write a unix script to do a sqlplus connection (using user id and password) to an oracle database and call a stored procedure. how could i do it? thanks to all
0
by: istruttorenuoto | last post by:
hi! I have some problems to call a stored procedure from an Unix Script. Here's the script stty istrip stty erase ^H export ORACLE_BASE=/product/oracle export...
1
by: ora2000 | last post by:
Hi I would like to create a unix script to connect to an ORACLE database using a oracle package. Also this script should provide functionality to call an oracle procedure that contains a parameter...
26
by: seemagoyal | last post by:
Hi, I don't have any experiance of UNIX and oracle. but i have got a short assignment for writing a unix script that will call a stored procedure. this script has to run this procedure after...
1
by: Vinod Sadanandan | last post by:
Cross Platform Migration An Unproblematic Approach (Windows-UNIX ) Oracle 10\11g The principal restriction on cross-platform transportable database is that the source and destination platform...
5
by: vishal | last post by:
Hi, I am writing my first script to execute a Oracle procedure through a unix script. Could you tell me how do I do error handling here? How do I know in my script if the procedure executed...
1
by: rajpar | last post by:
Environment: Solaris (client + server) db2 version 7.2 latest fixpak (DB2 v7.1.0.111", "s050516" and "U803330") Compiler: gcc Here is my SP code executed on the client: CREATE PROCEDURE...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.