← Statistics
Oracle · Statistics

How to check optimizer statistics on a table in Oracle

Check a table optimizer statistics: row count, blocks, sample size, when they were last gathered, and whether they are locked.

Tested on11g12c18c19c21c23ai26ai

Check the optimizer statistics stored on a table: row count, blocks, sample size, when they were last gathered, and whether they are locked.

-- Table statistics (all releases)
SELECT owner, table_name, num_rows, blocks, avg_row_len,
       sample_size,
       TO_CHAR(last_analyzed,'YYYY-MM-DD HH24:MI') AS last_analyzed
FROM   dba_tables
WHERE  owner = UPPER('&&owner')
  AND  table_name = UPPER('&&table_name');

-- Are the stats locked?
SELECT stattype_locked
FROM   dba_tab_statistics
WHERE  owner = UPPER('&owner')
  AND  table_name = UPPER('&table_name')
  AND  object_type = 'TABLE';
StatisticsDBMS_STATSDBA_TABLES