统计informix数据库表记录数

4182阅读 0评论2012-03-18 daydaycome
分类:LINUX

统计informix数据库某用户表记录数
用法:
table_count_inf.sh dbname username

table_count_inf.sh内容如下:

if [ "$#" -ne "2" ]
then
    echo "useage: $0 dbname user"
    exit
fi
dbsname="$1"
owner="$2"

#取表名
echo "unload to tmp.txt
select tabname from systables where owner='$owner' order by 1;" >  table.sql
dbaccess $dbsname table.sql
awk -F"|" '{print $1}' tmp.txt >tables.txt
rm tmp.txt

#生成统计各表记录数的sql语句
echo "unload to count_inf.txt" > tmp.sql
for i in `cat tables.txt`
do
    echo "select '$i',trunc(count(*),0)||\"\" from $i 
    union all">>tmp.sql
done
sed '$d' tmp.sql >  file.sql
echo ";" >>file.sql
rm tmp.sql

#统计各表行数,结果到count_inf.txt
dbaccess $dbsname file.sql
rm table.sql file.sql tables.txt

上一篇:用sqlplus的spool导文本文件
下一篇:oracle统计表记录数(count(*)实现)