Identify a table with maximum rows in Oracle

后端 未结 7 1480
猫巷女王i
猫巷女王i 2021-01-13 08:15

I have a set of tables in Oracle and I would like to identify the table that contains the maximum number of rows.

So if, A has 200 rows, B has 345 rows and C has 120

7条回答
  •  青春惊慌失措
    2021-01-13 08:21

    David Aldridge correctly points out that querying all_tables could give incorrect results due to missing or stale table statistics. But there is also a problem with using user_segments; Deleted blocks beneath the high water mark would still be counted for the size of the table.

    Example:

    SQL>create table t as select * from all_objects
    
    Table created.
    
    SQL>select blocks, bytes from user_segments where segment_name = 'T';
    
        BLOCKS      BYTES
    ---------- ----------
           768    6291456
    
    SQL>delete from t
    
    52676 rows deleted.
    
    SQL>commit;
    
    Commit complete.
    
    SQL>select count(*) from t;
    
      COUNT(*)
    ----------
             0
    
    SQL>select blocks, bytes from user_segments where segment_name = 'T';
    
        BLOCKS      BYTES
    ---------- ----------
           768    6291456
    
    SQL>truncate table t;
    
    Table truncated.
    
    SQL>select blocks, bytes from user_segments where segment_name = 'T';
    
        BLOCKS      BYTES
    ---------- ----------
             8      65536
    

提交回复
热议问题