while read ID ; do sqlplus -s username/passwd << EOF select count(PC.ptcpnt_$ID) from ... .. ..; exit; EOF done < myfile