Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
In shell script I am inserting the record in to the table.After excuation the script output is commit complete which is fine but I need my echo should be display like "Account created"
#!/bin/ksh
.
.
.
.
.
.inst dev000
sqlplus -s username/password EOFInsert into table (column1,column2,column3) values ($gblid,$sysid,$crdate);
commit;
exit
EOF=============================
Script Output #1:commit complete.
Instead of above line o/p should be "Account created".
How I can do this?
========================================================
Script Output#2:
ORA-00001: unique constraint violated
If output is like this then o/p should be "Account can't created"
How I can do this?
============================How I can trap oracle error?

Do you know which command specifically creates these error messages? And do you know what the return codes are for success/error?
If so, then just execute the command and redirect the output to /dev/null . Check the return code, and if it was successfull, echo "Account Created" and if it wasn't echo "Account Can't be Created" or something like that. Here's a little example code:
mycommand -flag argument &> /dev/null
if [ $? -e 0 ] ; then
echo "Account created"
exit 0
fi
echo "Account can't be created"
exit 1I think that's how it goes

Rather than send output to /dev/null, I would suggest directing it to a disk file. If you get failure, you would want to see the exact reason for it.
To get sqlplus to exit with a failure status code, the first line of your script should be:
whenever sqlerror exit failure
That will allow you to test success or failure of sqlplus per zeroguy.

This code would do .
tmpfile=`mktemp`
touch $tmpfile
chmod 777 $tmpfilesqlplus -s username/password /dev/null 2>&1
SET SERVEROUTPUT OFF
SET FEEDBACK OFF
declare
fl utl_file.file_type ;
.
.
begin
fl := pkg_util.fopen ('$tmpfile', 'w') ;
Insert into table (column1,column2,column3) values ($gblid,$sysid,$crdate);
commit;
if sql%rowcount > 0 then
utl_file.put_line (fl, 'Account Created');
else
utl_file.put_line (fl, 'Error Creating A/C')
utl_file.fclose (fl) ;
END ;
/
exit
!
. ${tmpfile}
rm -f ${tmpfile}

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |