If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Give error code from sqlplus to shell script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-05-02, 19:46
Fajr Fajr is offline
Registered User
 
Join Date: Dec 2002
Posts: 5
Give error code from sqlplus to shell script

Hello,
First sorry for my englis I'm french.

I try to use 'whenever sqlerror exit sql.sqlcode' to pass the SQL error code to the bash but it doesn't work:
This is my script It is in a file file_name.ksh :


sqlplus -s /nolog << END | tee -a $LogFile
connect $CidUser/$CidPwd
whenever sqlerror exit sql.sqlcode
alter session enable parallel dml;
select /*+ parallel (HIST_REQUEST 4) */ count(0) "HIST_REQUEST" from HIST_REQUEST ;
select /*+ parallel (HIST_REQUEST_PARAM 4) */ count(0) "HIST_REQUEST_PARAM" from HIST_REQUEST_PARAM ;

set timing on;
DECLARE
CURSOR req_cursor(nbdays NUMBER) IS
SELECT /*+ parallel (REQUEST 4) */
DISTINCT REQUEST_ID
FROM REQUEST
WHERE PARENT_REQUEST_ID IS NULL
AND REQUEST_STATUS_CODE in ( SELECT /*+ PARALLEL (REQUEST_STATUS 2 ) */ REQUEST_STATUS_CODE FROM REQUEST_STATUS WHERE REQUEST_PROCESSED = 1)
AND TRUNC ( SYSDATE ) - TRUNC (REQUEST_STATUS_CHANGE_DATE ) >= nbdays ;
nbloop integer := 0;
nbloop2 integer := 0;
maxloop integer := 4000;
BEGIN
FOR req_record IN req_cursor(40) LOOP
/*
** Delete the child REQUEST and the associated REQUEST_PARAM
** This process need to be done recursively.
*/
PURGE_REQUEST_PRCA (req_record.REQUEST_ID);
if (nbloop = 100) then
COMMIT;
nbloop2 := nbloop2 + nbloop;
nbloop := 0;
end if;
nbloop := nbloop +1;
-- EXIT WHEN nbloop2 >= maxloop;

END LOOP;

COMMIT;

EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
END;
/
select /*+ parallel (HIST_REQUEST 4) */ count(0) "HIST_REQUEST" from HIST_REQUEST ;
select /*+ parallel (HIST_REQUEST_PARAM 4) */ count(0)"HIST_REQUEST_PARAM" from HIST_REQUEST_PARAM ;
END
echo $?



The echo $? give 0 and Idon't know how??? I gonna be crazy!!
Thanks a lot for your help!!
Reply With Quote
  #2 (permalink)  
Old 12-06-02, 07:22
WingMan WingMan is offline
Registered User
 
Join Date: Aug 2002
Location: UK
Posts: 87
if the SQL is run in a child process then it will be this child process that is exited and not the parent script you are running. (i think)

Code:
After calling the child process try something like
if [ $? = "0" ]; then
 echo "child process Ran ok"
else
 echo "child process failed"
 exit 3
fi
Reply With Quote
  #3 (permalink)  
Old 12-06-02, 12:04
Fajr Fajr is offline
Registered User
 
Join Date: Dec 2002
Posts: 5
GIve SQL error to the script

Quote:
Originally posted by WingMan
if the SQL is run in a child process then it will be this child process that is exited and not the parent script you are running. (i think)

Code:
After calling the child process try something like
if [ $? = "0" ]; then
 echo "child process Ran ok"
else
 echo "child process failed"
 exit 3
fi

Thanks a lot for your help.
So i don't know if it's a child process and i don't think so.
The 'echo $?' instruction I have written after the SQL script is done to see what is the error code. But it's always 0 and i don't understand. I have written a call to a SQL stocked procedure which doesn't exist to exit with an error but it 's always 0.
That's the real problem.
Reply With Quote
  #4 (permalink)  
Old 12-10-02, 07:38
WingMan WingMan is offline
Registered User
 
Join Date: Aug 2002
Location: UK
Posts: 87
'echo $?' will return the error status of the last command executed.

Have you tried just one SQL statement like (below) and tried to test $?
Code:
select /*+ parallel (HIST_REQUEST_PARAM 4) */ 
count(0)"HIST_REQUEST_PARAM" 
from HIST_REQUEST_PARAM ;
Reply With Quote
  #5 (permalink)  
Old 03-26-08, 13:09
ndb ndb is offline
Registered User
 
Join Date: Mar 2008
Posts: 1
Reraise exception in your exception handler routine.

EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
RAISE;
END;
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On