Sql command inside shell script runs without giving anything back as outout


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sql command inside shell script runs without giving anything back as outout
# 1  
Old 07-07-2014
Sql command inside shell script runs without giving anything back as outout

Code:
#!/bin/sh
# This script returns the number of rows updated from a function

echo "The execution is starting ....."
sqlplus -silent $UP <<EOF
set serveroutput on
set echo off
set pagesize 0
VAR no_rows_updated NUMBER;
EXEC :no_rows_updated :=0;
DECLARE
CURSOR c_update is
SELECT * FROM BELK_BOOKS FOR UPDATE OF AUTHOR_NAME;
BEGIN
FOR REC IN c_update
LOOP
   UPDATE Belk_Books 
   SET AUTHOR_NAME='ASFAKUL'
   WHERE CURRENT OF c_update;
   :no_rows_updated:=c_update%ROWCOUNT;
   --no_rows_updated:=no_rows_updated+1;
END LOOP;
Commit;
--SELECT c_update%ROWCOUNT INTO no_rows_updated from Dual;
--no_rows_updated:=c_update%ROWCOUNT;

--DBMS_OUTPUT.PUT_LINE(no_rows_updated);
EXCEPTION 
WHEN OTHERS THEN
    :no_rows_updated:=SQLCODE;
                ROLLBACK;
END;
/
exit :no_rows_updated ;
EOF

error_exit=$?
if [ $error_exit -ne 0 ]; then
    echo "There was an error or 0 rows updated"
else
   echo "The number of rows updated is : $error_exit"
fi

here is the code I am trying to run , please help
# 2  
Old 07-07-2014
What is the output? What errors are you getting?
# 3  
Old 07-07-2014
Quote:
Originally Posted by vbe
What is the output? What errors are you getting?
"There was an error or 0 rows updated" I am getting this . But 3 rows were updated in the sql , so I should have gotten the second output with counts of rows updated (i.e. 3)
# 4  
Old 07-08-2014
Quote:
Originally Posted by LoneRanger
"There was an error or 0 rows updated" I am getting this . But 3 rows were updated in the sql , so I should have gotten the second output with counts of rows updated (i.e. 3)
No you shouldn't.
Your shell script is working just like you have programmed it. Because 3 rows were updated, the test $error_exit not equal to 0 is TRUE:

Code:
if [ $error_exit -ne 0 ]; then # TRUE because $error_exit is 3, which is not equal to 0
    echo "There was an error or 0 rows updated"
 ...
    ...
...

and hence you are seeing the output you have programmed.
# 5  
Old 07-08-2014
Quote:
Originally Posted by durden_tyler
No you shouldn't.
Your shell script is working just like you have programmed it. Because 3 rows were updated, the test $error_exit not equal to 0 is TRUE:

Code:
if [ $error_exit -ne 0 ]; then # TRUE because $error_exit is 3, which is not equal to 0
    echo "There was an error or 0 rows updated"
 ...
    ...
...

and hence you are seeing the output you have programmed.
Oh Yes !!! Thanks . I see my erorr Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

CUT command not giving correct result inside loop

Hi, i have a source file and have 3 columns and separated by "|" .i want to split this 3 columns in different variable.When i am executing this values indivisually giving correct result but when the same execute inside a for loop,it's giving issues. Src file(jjj.txt) -------... (8 Replies)
Discussion started by: raju2016
8 Replies

2. Shell Programming and Scripting

Can i use if else inside expect command in shell script?

hii,, I am trying to automate jira. during my scripting using bash script, in the terminal i got the terminal message like this: "Configure which ports JIRA will use. JIRA requires two TCP ports that are not being used by any other applications on this machine. The HTTP port is where you... (1 Reply)
Discussion started by: nithinfluent
1 Replies

3. Shell Programming and Scripting

Ampersand not giving back the control (Korn shell)

OS version : AIX 6.1 Shell : Korn When you 'postfix' a command with ampersand (&) , it is supposed to run in the background and give you back the control. I tested this with ping command (by default it pings every 1 second ) After I ran the below ping command with ampersand, I pressed... (3 Replies)
Discussion started by: polavan
3 Replies

4. Shell Programming and Scripting

CRON shell script only runs correctly on command line

Hi, I'm new to these forums, and I'm hoping that someone can solve this problem... To make things short: I have DD-wrt set up on a router. I'm trying to run a script in CRON that fetches the daily password from my database using SSH. CRON is set like so(in web interface): * * * *... (4 Replies)
Discussion started by: louieaw
4 Replies

5. Shell Programming and Scripting

How to monitor a command inside shell script

Hi All, Is there any way to monitor a command inside shell script ? I have a script inside which I have a tar command which zips around 200GB data. tar zcvf $Bckp_Dir/$Box-BaseBackup-$Day.tar.gz * --exclude 'dbserver_logs/*' --exclude postmaster.pid --exclude 'pg_xlog/*' I want to... (3 Replies)
Discussion started by: sussus2326
3 Replies

6. Shell Programming and Scripting

Shell script runs fine in Solaris, in Linux hangs at wait command

HI, I have a strange problem. A shell script that runs fine on solaris. when i ported to linux, it started hanging. here is the core of the script CFG_FILE=tab25.cfg sort -t "!" -k 2 ${CFG_FILE} | egrep -v "^#|^$" | while IFS="!" read a b c do #echo "jobs output" #jobs #echo "jobs... (13 Replies)
Discussion started by: aksaravanan
13 Replies

7. Shell Programming and Scripting

Script Runs fine but not giving any output

Hi, My script is running with no erros but not giving any output can anyonehelp. #!/bin/ksh . /home/application/bin/application.env OUTFILE=Result.txt PROD_PASSWORD=`${GET_PWD} -f ${PWD_FILE_PATH} -s ${PROD_SERVER} -u ${PROD_USER}` echo "1)To get the book last loaded details " read... (7 Replies)
Discussion started by: jagadish_gaddam
7 Replies

8. Shell Programming and Scripting

Shell script which runs sql script

Hi all, I need a shell script which runs a sql script but I couldn't find how to finish it. This is the code that I have: #! /usr/bin/ksh export SHELL=/bin/ksh export ORACLE_SID=database export ORACLE_HOME=/opt/oracle/product/9.2.0.8 sqlplus user <<EOF @/path/path/path/scriptname.sql... (3 Replies)
Discussion started by: Geller
3 Replies

9. Shell Programming and Scripting

mv command is giving error in shell script

Hi, In my shell script when I am using mv command using shell variables it is giving me error of syntax. Following is the shell script: file_edifice="*.txt" fquote="'" fdquote=\" for file in $file_edifice do file_name=$fquote$file$fquote tofile_name=`date... (5 Replies)
Discussion started by: gammit
5 Replies

10. Shell Programming and Scripting

How to run an SQL script inside a shell

How do I create a K Shell which would silently (without user input) logon to Oracle and run an SQL script? Any help will be greatly appreciated. Steve (1 Reply)
Discussion started by: stevefox
1 Replies
Login or Register to Ask a Question