Friday, 4 July 2025

Filled under:

 WITH table_defs AS (

  SELECT 

    c.owner,

    c.table_name,

    LISTAGG(c.column_name || ':' || c.data_type || ':' || c.data_length, ',') 

      WITHIN GROUP (ORDER BY c.column_id) AS col_signature

  FROM all_tab_columns c

  WHERE c.owner NOT IN (

    'SYS', 'SYSTEM', 'XDB', 'OUTLN', 'MDSYS', 'ORDDATA', 'ORDSYS',

    'CTXSYS', 'DBSNMP', 'APPQOSSYS', 'AUDSYS', 'DVSYS',

    'GSMADMIN_INTERNAL', 'ANONYMOUS', 'WMSYS', 'OLAPSYS',

    'LBACSYS', 'SI_INFORMTN_SCHEMA'

  )

  GROUP BY c.owner, c.table_name

),

table_sizes AS (

  SELECT 

    owner, 

    segment_name AS table_name, 

    ROUND(SUM(bytes)/1024/1024, 2) AS size_mb

  FROM dba_segments 

  WHERE segment_type = 'TABLE'

  GROUP BY owner, segment_name

)

SELECT 

  d.col_signature,

  COUNT(*) AS table_count,

  LISTAGG(d.owner || '.' || d.table_name || ' (' || NVL(s.size_mb, 0) || ' MB)', ', ')

    WITHIN GROUP (ORDER BY d.owner, d.table_name) AS tables_with_size

FROM table_defs d

LEFT JOIN table_sizes s

  ON d.owner = s.owner AND d.table_name = s.table_name

GROUP BY d.col_signature

HAVING COUNT(*) > 1

ORDER BY table_count DESC;


0 comments:

Post a Comment