请问,如何查询Oracle中多个表(大概四五十个)的数据总的记录?select count(1) from tablename1;这个通过查询单个表得出,有没有其他什么方法

解决方案 »

  1.   

     先exec dbms_stats.gather_schema_stats
    接着 select NUM_ROWS from user_tab_statistics;
    适用于表数据变化不频繁的情况下
      

  2.   

    select sum(NUM_ROWS) from ALL_TABLES where TABLE_NAME in ('table1','table2',...);
      

  3.   


    利用这条语句得到的结果是:
    SUM(NUM_ROWS)          
    ---------------------- 
                           1 rows selected不知道为什么结果不能正确显示
      

  4.   

    如果有相关的PL SQL语句也是可以的 谢谢
      

  5.   

    或者换成USER_TABLES试试不过查询前需要analyze一下,
    analyze table table1 estimate statistics;
    或者同#1的方法这两种都是分析表收集信息。
      

  6.   


    --exec dbms_stats.gather_schema_stats
    analyze TABLE test estimate statistics;
    analyze TABLE test1 estimate statistics;
    select sum(num_rows) 
    from all_tables 
    where table_name in('test','test1');
     analyze TABLE test 成功。
     analyze TABLE test1 成功。
    SUM(NUM_ROWS)          
    ---------------------- 
                           1 rows selected还是没有结果 
    不明白为什么
    请分析一下 
    谢谢
      

  7.   

    如果要多个表的总记录,select sum(NUM_ROWS) from ALL_TABLES where TABLE_NAME in ('TABLE1','TABLE2',...); 一定要大写
    如果想看每个表的数据总数:select TABLE_NAME, sum(NUM_ROWS) from ALL_TABLES where TABLE_NAME in ('TABLE1','TABLE2',...) group by TABLE_NAME; 
    表名,大写哦