oracle统计表记录数

用法:

sh table_count_ora.sh dbname dbuser userpwd

table_count_ora.sh内容如下:

  1. if [ $# -ne 3 ]; then
  2.     echo "usage: $0 dbname dbuser userpwd"
  3.     exit;
  4. fi    
  5. dbname=$1
  6. dbuser=$2
  7. userpwd=$3
  8. sqlplus $dbuser/$userpwd@$dbname << !
  9. set linesize 2500;
  10. set pagesize 0;
  11. set sqlnumber off;
  12. set trimspool on;
  13. set feedback off;
  14. #取数据库表名
  15. spool tmp.txt;
  16. select lower(table_name) from user_tables order by 1;
  17. spool off;
  18. !
  19. echo "debug"
  20. sed '/^SQL>/d' tmp.txt > tables.txt
  21. rm tmp.txt

  22. #生成统计各表记录数的sql
  23. > tmp.sql
  24. for i in `cat tables.txt`
  25. do
  26.     echo "select '$i'||'|'||count(*)||'|' from $i
  27.     union all">>tmp.sql
  28. done
  29. sed '$d' tmp.sql > file.sql
  30. echo ";" >>file.sql
  31. rm tmp.sql

  32. #执行统计各表数据的sql
  33. sqlplus $dbuser/$userpwd@$dbname << END
  34. set linesize 2500;
  35. set pagesize 0;
  36. set sqlnumber off;
  37. set trimspool on;
  38. set feedback off;
  39. set numformat 99999999999.9;
  40. spool tmp.txt
  41. @file.sql
  42. spool off
  43. END
  44. sed '/^SQL>/d' tmp.txt > count_ora.txt
  45. rm tables.txt tmp.txt file.sql


09-20 00:17