合 使用脚本统计Oracle和MySQL全库的表行数
Oracle
方式一:块或存储过程
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | drop table t_oracle; create table t_oracle( table_name varchar2(64), table_rows number ); declare v_count number :=0; v_sql varchar2(3000); begin for cur in (select table_name from user_tables) loop v_sql :='select /*+ parallel(4) */ count(*) from '|| cur.table_name ; execute IMMEDIATE v_sql into v_count; insert into t_oracle values(cur.table_name,v_count); commit; end loop; end; select * from t_oracle; |
方式二:SQL直接查询
1 2 3 4 | select table_name, 'select '''||d.table_name ||''' tb_name , count(*) tb_rows from '||d.table_name ||' union all' sql_count from user_tables d order by table_name; |
MySQL
1 2 3 4 5 | select table_name, concat('select ''', d.table_name ,''' tb_name , count(*) tb_rows from ',d.table_name ,' union all') sql_count from information_schema.tables d where d.table_schema='lhrdb' order by table_name; |