How To Catch Sql Error In Shell Script
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site
Whenever Sqlerror
About Us Learn more about Stack Overflow the company Business Learn more sqlplus error handling in shell script about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss whenever sqlerror exit 1 shell script Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Managing error handling
Sqlplus Error Handling In Unix
while running sqlplus from shell scripts up vote 9 down vote favorite 4 #!/bin/sh echo "Please enter evaluate database username" read eval_user echo "Please enter evaluate database password" read eval_pass echo "Please enter the database name" read db_name LOGFILE=shell_log.txt $ORACLE_HOME/bin/sqlplus -s /nolog <<-EOF>> ${LOGFILE} connect $eval_user/$eval_pass@$db_name WHENEVER OSERROR EXIT 9; WHENEVER SQLERROR EXIT SQL.SQLCODE; DBMS_OUTPUT.put_line('Connected to db'); EOF if [ $? != 0 ] then
Capture Sqlplus Error In Shell Script
echo "The upgrade script failed. Please refer to the log results.txt for more information" echo "Error code $?" exit 0; fi I am entering garbage values trying to force this script to fail. But, annoyingly, it keeps moving ahead without any mention of any error code. What else needs to be done here? oracle shell sqlplus aix share|improve this question asked Feb 6 '13 at 16:35 roymustang86 1,936113573 Which OS user account are you running under? What database does the script login to? –APC Feb 11 '13 at 14:01 I tried your script, and the log file is capturing the error code. Here is the grab from the log file: ERROR: ORA-01017: invalid username/password; logon denied SP2-0734: unknown command beginning "DBMS_OUTPU..." - rest of line ignored. –Incognito Feb 12 '13 at 9:55 May I know, what're you getting in log file when you execute the script? –Incognito Feb 12 '13 at 11:18 add a comment| 5 Answers 5 active oldest votes up vote 7 down vote accepted +50 What Max says is correct. Try this modified script #!/bin/sh echo "Please enter evaluate database username" read eval
Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here. Search Forums Show whenever sqlerror exit sql.sqlcode shell script Threads Show Posts Tag Search Advanced Search Unanswered Threads Find All
Sqlplus Error Codes
Thanked Posts Go to Page... linux operating commands and unix operating commands How to catch sql error sqlplus exit code in script? Shell Programming and Scripting Thread Tools Search this Thread Display Modes #1 03-14-2014 ken6503 Registered User Join Date: http://stackoverflow.com/questions/14734131/managing-error-handling-while-running-sqlplus-from-shell-scripts May 2013 Last Activity: 6 October 2016, 1:50 PM EDT Location: Toronto Posts: 181 Thanks: 152 Thanked 3 Times in 3 Posts How to catch sql error in script? Hi Gurus, I have a script which send sql query to oracle db and return value to my script. dummy code like below: Code: sqlplus -s user/${PASSWD}@${ORACLE_SID} @${DIR}/query.sql > outputfile using above http://www.unix.com/shell-programming-and-scripting/245224-how-catch-sql-error-script.html code, when query has error, it send error to same out put file and exit code is 0, is there any way to make the sqlplus exit code other than 0 if the query contains any error? thanks in advance Remove advertisements Sponsored Links ken6503 View Public Profile Find all posts by ken6503 #2 03-14-2014 shamrock Registered User Join Date: Oct 2007 Last Activity: 10 October 2016, 3:03 PM EDT Location: USA Posts: 1,595 Thanks: 34 Thanked 156 Times in 147 Posts Put this line whenever sqleror exit sql.sqlcode as the first line of your "query.sql" file... Remove advertisements Sponsored Links shamrock View Public Profile Find all posts by shamrock #3 03-14-2014 Ditto Registered User Join Date: Mar 2014 Last Activity: 30 September 2015, 11:58 AM EDT Location: Toronto, Canada Posts: 70 Thanks: 5 Thanked 10 Times in 10 Posts Quote: Originally Posted by shamrock Put this line whenever sqleror exit sql.sqlcode as the first line of your "query.sql" file... That won't quite work as expected: Code: > more
for Help Receive Real-Time Help Create a Freelance Project Hire for a Full Time Job Ways to Get Help Ask a Question Ask for Help Receive Real-Time Help Create a Freelance Project Hire for a Full Time Job Ways to Get Help Expand Search Submit https://www.experts-exchange.com/questions/28496956/How-to-handle-oracle-sql-error-in-Unix-shell-script.html Close Search Login Join Today Products BackProducts Gigs Live Careers Vendor Services Groups Website Testing Store Headlines Experts Exchange > Questions > How to handle oracle sql error in Unix shell script? Want to Advertise Here? Solved How http://unix.stackexchange.com/questions/93041/error-out-shell-script-if-pl-sql-program-fails to handle oracle sql error in Unix shell script? Posted on 2014-08-13 Unix OS Oracle Database 1 Verified Solution 17 Comments 4,964 Views Last Modified: 2014-08-23 --- inpfile.sql SET FEEDBACK OFF SET HEADING OFF SET shell script ECHO OFF SET VERIFY OFF SET PAGESIZE 0 SET TERMOUT OFF whenever sqlerror exit 9 SPOOL 'test.txt' declare v number; begin SELECT EMPNO into v FROM ABC WHERE DENO = 999 ; end; SPOOL OFF; EXIT; --- unix file sqlplus scott/tiger@orcl @inpfile.sql if [ $? -eq 0 ] then echo "last command exit status needs to be checked" exit else echo in shell script "last command exit status is successful" fi When I run the Unix shell script then it stopped in sqlplus . In sql query there is no data present and I do not handle it in exception block. So I am going to capture the error through whenever sqlerror exit 9. It does not return the message "last command exit status needs to be checked". When unix shell script executed then the cursor stops on sqlplus. What is wrong with the code ? Please help. 0 Question by:digs developer Facebook Twitter LinkedIn Google LVL 34 Active today Best Solution byjohnsone My expertise is Oracle. I don't know how you would do that with SQL Server. I would suggest redirecting output to a file and searching the file like the examples here, but I don't know what to look Go to Solution 17 Comments LVL 34 Overall: Level 34 Oracle Database 33 Unix OS 7 Message Active today Expert Comment by:johnsone2014-08-13 On a quick look, you are missing a / to signal the end of the PL/SQL block. SET FEEDBACK OFF SET HEADING OFF SET ECHO OFF SET VERIFY OFF SET PAGESIZE 0 SET TERMOUT OFF whenever sqlerror exit 9 SPOOL 'test.txt' declare v number; begin SELECT EMPNO into v FROM ABC WHERE DENO = 999 ; end; / SPOOL OFF; EXIT;
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Error out shell script if PL/SQL program fails up vote 1 down vote favorite In the shell script, I am calling a PL/SQL stored procedure. sqlplus -s <