Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check whether sqlplus query returned rows

Status
Not open for further replies.

emikoo

Technical User
Jul 12, 2002
37
NL
Hi,

We run a sqlplus query and in a script export it to a text file. Now we only want to trigger a sendmail event, if the query returned at least one row. ie: if the query returned no rows, the sendmail event should not be triggered.

How can this be accomplished. Thnxs for your help.

EK
 
The way I've done this in one of my scripts is:

lines=`wc -l <textfile>| tr -s ' ' ' ' | cut -f2 -d' '`
if [ $lines -eq 0 ]; then
echo <textfile> is empty
exit
else
sendmail stuff
fi

HTH


 
ok thnxs. I am now able to attribute the number of lines from the sql query to the variable $lines (if number of lines =4 this means no rows returned). But can not get the &quot;if&quot; statement to work. What is wrong with this statement:

if [ $lines -eq 4 ]; then
echo <textfile> is empty
exit
else
sendmail stuff
fi
 
Are you getting any error message? Just on the offchance (we've all done this sometime), you're not using <textfile> literally are you? It should of course be replaced by your real filename. And you are including spaces within the test condition (ie [<sp>$lines<sp>-eq<sp>4<sp>])?HTH.
 
There's a FAQ on the subject - faq822-2218 Mike
________________________________________________________________

&quot;Experience is the comb that Nature gives us, after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top