假设我不是管理员 无法通过dba_tables查询出该表的行数
这个表大概有六亿行左右的数据,我试了下 count(*)和count(主键)
根本跑不出来  还有没有其他的好办法!

解决方案 »

  1.   

    user_tables 和 all_tables 还能查行数???。开玩笑吧。如果不要求精确,可以根据表段大小/ 每行占用的大小 得出大概值。
      

  2.   

    这个count(1) 怎么理解?
      

  3.   

    的确用11分钟得出了结果,其他的方法基本上都跑不出来。
    我查了下 貌似都说 count(1) 和count(*)的效率差别不大啊~
      

  4.   


    /*
    COUNT returns the number of rows in the query. You can use it as an aggregate or analytic function.If you specify DISTINCT, then you can specify only the query_partition_clause of the analytic_clause. The order_by_clause and windowing_clause are not allowed.If you specify expr, then COUNT returns the number of rows where expr is not null. You can count either all rows, or only distinct values of expr.If you specify the asterisk (*), then this function returns all rows, including duplicates and nulls. COUNT never returns null.
    */
      

  5.   


    /*
    如果你的数据表没有主键,那么count(1)比count(*)快
    如果有主键的话,那主键(联合主键)作为count的条件也比count(*)要快
    如果你的表只有一个字段的话那count(*)就是最快的啦
    count(*) count(1) 两者比较。主要还是要count(1)所相对应的数据字段。
    如果count(1)是聚索引,id,那肯定是count(1)快。但是差的很小的。
    因为count(*),自动会优化指定到那一个字段。所以没必要去count(?),用count(*),sql会帮你完成优化的
    */
      

  6.   

    这里面可以的吧select u.table_name,u.num_rows as 该表的行数 from user_tables u
    where u.table_name='table_name'
      

  7.   


    是的啊 dba_tables 和user_tables 这两个表中 都可以通过num rows 查出来
      

  8.   

    我刚看了下 user_tables 里面numrows 取自 sys.tab$ 。这里面的ROWCNT 就是空呢。
    你们的有值么,这个难道和oracle系统参数有关系?
      

  9.   

     DBA_TABLES >= ALL_TABLES >= USER_TABLES  DBA_TABLES意为DBA拥有的或可以访问的所有的关系表。  ALL_TABLES意为某一用户拥有的或可以访问的所有的关系表。  USER_TABLES意为某一用户所拥有的所有的关系表。如果楼主的数据库 在表字典里 是记录表行数的。可以用 all_tables 试试
      

  10.   

    select u.table_name, u.num_rows as 该表的行数
      from user_tables u
    这个表的行数是不准滴