To find the count of records from tables present inside a file.

hi gurus,

I am having a file containing a list of tables.i want to find the count of records inside thes tables.
for this i have to connect into database and i have to put the count for all the tables inside another file i used the following loop once all the tablenames are inside the file.

script :
for line in `cat tablenames`
do
#echo $line
sqlplus -s username/password@dbname << ! > table_count
set lines 1000 pages 0
declare
tab_name varchar2(50);
begin
tab_name:=$line
select count(*) from tab_name;
end;

!
done

but the table_count turns out to be = 0 after this executes....
Can anyone provide me with the correct approach.Its urgent.

Try this:

nawk -v v="'" '{ print("select " v ":" $1":" v "||count(*) from "$1";"); }' tablenames > count.sql

sqlplus -s username/password@dbname <<! > count.log
set linesize 1000 pagesize 0 heading off feedback off trimspool on;
@count.sql
!

grep "^:" count.log

In the log file you will have the output in this format:

:TABLE1:10
:TABLE2:20
:TABLE3:30
...
:TABLEn:<count>

In this manner you can easily grep/cut the information you need from the log file.