Bourne Shell: Clean Display of stored procedure's output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bourne Shell: Clean Display of stored procedure's output
# 1  
Old 04-14-2008
Bourne Shell: Clean Display of stored procedure's output

Environment: Sun UNIX

Language: Bourne Shell

I have the following script and it works fine. Unfortunately, from user's perspective, it looks very messy because the user is able to see the output of the process caused by the print command.

Is there a better way to overcome it?

Here's the code:

SPOOL_FILE = /tmp/spool.txt
A=1000
B=2000
DB_USER=user123
DB_USER_PASSWD=123
DB_INSTANCE=DB1

$ORACLE_HOME/bin/sqlplus /NOLOG @<<!
set echo off

Connect $DB_USER/$DB_USER_PASSWD@$DB_INSTANCE

var RETURN_CODE VARCHAR2(4);
var MAX_OUT VARCHAR2(3);
var PATH_OUT VARCHAR2(10);

exec TEST_API.GET_RECORD('$A', '$B', :RETURN_CODE, :MAX_OUT, :PATH_OUT);

spool $SPOOL_FILE
print RET_CODE;
print MAX_OUT;
print PATH_OUT;
spool off
exit
!

# Reading the spool file to get stored procedure's returned values
exec 3<&0
exec 0<$SPOOL_FILE
while read line
do
echo $line
if [ "$line" = 'RET_CODE' ]; then
read line
read line
RET_CODE=$line
fi
if [ "$line" = 'MAX_OUT' ]; then
read line
read line
CUR_MAX=$line
fi
if [ "$line" = 'PATH_OUT' ]; then
read line
read line
CUR_PATH=$line
fi
done
exec 0<&3

echo "Current Max Value is " $CUR_MAX
echo "Current Path is " $CUR_PATH
# 2  
Old 04-14-2008
Hammer & Screwdriver What about redirectig the standard output?

Normally, you can re-direct various output to a file. For example:

lp myfile.txt >>work.log 2>>work.err

this would print myfile.txt
and send any confirmations to file work.log
and send errors to file work.err

To suppress this completely, often output is redirected as:

lp myfile.txt >/dev/null
# 3  
Old 04-14-2008
Add the redirections to your sqlplus command :
Code:
$ORACLE_HOME/bin/sqlplus /NOLOG >/dev/null 2>&1 @<<!

In your script, you can read the spool file without playnig with exec :
Code:
# Reading the spool file to get stored procedure's returned values
while read line
do
   echo $line
   . . .
done < $SPOOL_FILE

Jean-Pierre.

Last edited by aigles; 04-15-2008 at 05:30 AM.. Reason: typo error on stdout redirection operator
# 4  
Old 04-14-2008
Thanks for helping. I will try out all your suggestion when I am in the office. I really appreciate your help because my deadline is almost overdue.
# 5  
Old 04-15-2008
In my environment, without the exec, the value stored in the variable assigned inside the while loop cannot be referred. In the code as follows, you'll get "123" instead of the value obtained from the SPOOL_FILE at the last echo statement. I have no idea why. I was struggling with this problem before discovering exec method.


CUR_MAX=123
# Reading the spool file to get stored procedure's returned values
exec 3<&0
exec 0<$SPOOL_FILE
while read line
do
echo $line
if [ "$line" = 'MAX_OUT' ]; then
read line
read line
CUR_MAX=$line
fi
done
exec 0<&3

echo "Current Max Value is " $CUR_MAX


Meanwhile, the suggestion to add "</dev/null 2>&1" in the following does not prevent print section from being displayed Smilie

$ORACLE_HOME/bin/sqlplus /NOLOG </dev/null 2>&1 @<<!
# 6  
Old 04-15-2008
Quote:
Originally Posted by totziens
In my environment, without the exec, the value stored in the variable assigned inside the while loop cannot be referred. In the code as follows, you'll get "123" instead of the value obtained from the SPOOL_FILE at the last echo statement. I have no idea why. I was struggling with this problem before discovering exec method.


CUR_MAX=123
# Reading the spool file to get stored procedure's returned values
exec 3<&0
exec 0<$SPOOL_FILE
while read line
do
echo $line
if [ "$line" = 'MAX_OUT' ]; then
read line
read line
CUR_MAX=$line
fi
done
exec 0<&3

echo "Current Max Value is " $CUR_MAX


Meanwhile, the suggestion to add "</dev/null 2>&1" in the following does not prevent print section from being displayed Smilie

$ORACLE_HOME/bin/sqlplus /NOLOG </dev/null 2>&1 @<<!
I make a typo mistake, the redirection for stdout is > (and not <) :
Code:
$ORACLE_HOME/bin/sqlplus /NOLOG >/dev/null 2>&1 @<<!

Jean-Pierre.
# 7  
Old 04-15-2008
Thanks, Jean-Pierre. It definitely improves but I still see the following output being displayed. I wonder whether it can be eliminated completely.

> ./cc.sh
SQL> print RETURN_CODE;

RETURN_CODE
--------------------------------------------------------------------------------
000000

SQL> print MAX_OUT;

MAX_OUT

SQL> print PATH_OUT;

PATH_OUT

SQL> spool off
Current Max Value is 556
Current Path is main/43
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh and Oracle stored procedure output in logfile

Friends, I pass some runtime arguments (date, number) through ksh script to Oracle procedure, use input value and pass it on to procedure. Oracle procedure gets input value, run query and logs everything in the logfile. I'm facing with couple of challenges 1. Even though I pass all... (5 Replies)
Discussion started by: homer4all
5 Replies

2. Shell Programming and Scripting

Run stored procedure from shell script

Hello all, I am trying to run stored procrdure from shell script which takes one argument. And also I want to verify in the script whether the script executed successfully. However the Stored procedure is not running from shell script. Manually if I run it update the data in the table. Can... (29 Replies)
Discussion started by: PriyaSri
29 Replies

3. Shell Programming and Scripting

How to get OUT parameter of a stored procedure in shell script?

I am invoking a SQL script from shell script. This SQL script will invoke a stored procedure(which has the OUT parameter). I want to have the OUT parameter in the shell script as a variable. Is this possible? (6 Replies)
Discussion started by: vel4ever
6 Replies

4. Shell Programming and Scripting

How to call a stored procedure from shell program?

How to call a stored procedure from shell program (1 Reply)
Discussion started by: noorm
1 Replies

5. Shell Programming and Scripting

input stored procedure to shell program

Hello, I have to call the stored procedure as argument from the unix shell program. Looks like unix doesnt like, can someone comment pls USERID=scott PASSWD=xxxxxx PLSQLCALL=$2 STDT=`sqlplus /nolog <<END >> $LOGFILE conn ${USERID}/${PASSWD}@${ORACLE_SID} whenever sqlerror exit failure... (9 Replies)
Discussion started by: tvanoop
9 Replies

6. Shell Programming and Scripting

How to execute the stored procedure from shell script

How to execute the stored procedure from shell script and is there any possibility to print the dbms output in a log file. (2 Replies)
Discussion started by: dineshmurs
2 Replies

7. Shell Programming and Scripting

Call and redirect output of Oracle stored procedure from unix script

Hi, Can you assist me in how to redirect the output of oracle stored procedure from unix script? Something similar to what i did for sybase isql -U$MYDBLOG -D$MYDBNAME -S$MYDBSVR -P$MYDBPWD -o$MYFILE<< %% proc_my_test 8 go %% Thanks in advance - jak (0 Replies)
Discussion started by: jakSun8
0 Replies

8. Shell Programming and Scripting

Calling stored procedure from shell script

HI, I have a similar problem to thread 18264, only I couldn't get it to work. https://www.unix.com/showthread.php?t=18264 I have a stored procedure which is called by a shell script program. When I run the stored procedure alone or through the shell script, it works fine with output text... (3 Replies)
Discussion started by: dorisw
3 Replies

9. Shell Programming and Scripting

Shell arrays in oracle stored procedure

Is it possible to pass unix shell arrays in Oracle stored procedure? Is yes, how? Thanks (6 Replies)
Discussion started by: superprogrammer
6 Replies

10. Shell Programming and Scripting

calling stored procedure from shell script.

Hi All, This is a very starnge problem I am having. I have a shell script that calls a stored procedure. Here's my code in shell script: sqlplus "userid/pwd" @file.sql and file.sql has the following statement: exec my_storedProc; Now, when I execute my shell script, nothing... (2 Replies)
Discussion started by: priyamurthy2005
2 Replies
Login or Register to Ask a Question