Or even change the SQL to SELECT count(*) FROM v\$process WHERE spid = $xpid so you get immediately the number of records in the database for which spid = $xpid. It is faster, it saves on memory and you can plug it straight into the if.
CountZero
"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law