Skip to main content

Number of Tables by their Size in Oracle Database

Here I am giving an example to find out number of tables by their size (Bytes, KB, MB, GB and TB) in oracle database.

Query 1: [Bytes] Number of all tables accessible to the current user in Oracle database by their size grouped into predefined intervals.

SELECT size_interval,
       count(*) AS no_of_tables
  FROM (SELECT DATA.segment_name table_name,
              CASE
               WHEN DATA.bytes > 1000000000
               THEN '1b Bytes and more'
               WHEN DATA.bytes > 1000000
               THEN '1m - 1b Bytes'
               WHEN DATA.bytes > 1000
               THEN '1k - 1m Bytes'
               WHEN DATA.bytes > 100
               THEN '100 - 1k Bytes'
               WHEN DATA.bytes > 10
               THEN '10 - 100 Bytes'
               ELSE '0 - 10 Bytes'
              END AS size_interval
        FROM (SELECT us.segment_name,
                     sum(us.bytes) bytes
                FROM sys.user_segments us,
                     sys.all_tables at
               WHERE at.table_name = us.segment_name
                 AND us.segment_type = 'TABLE'
                  -- excluding some Oracle maintained schemas 
                 AND AT.owner NOT IN ('ANONYMOUS','CTXSYS',
                                      'DBSNMP','EXFSYS', 
                                      'LBACSYS', 'MDSYS', 
                                      'MGMT_VIEW','OLAPSYS', 
                                      'OWBSYS','ORDPLUGINS', 
                                      'ORDSYS', 'SI_INFORMTN_SCHEMA', 
                                      'SYS','SYSMAN',
                                      'SYSTEM', 'TSMSYS',
                                      'DIP', 'WKPROXY',
                                      'WMSYS','XDB',
                                      'APEX_040000', 'APEX_PUBLIC_USER', 
                                      'FLOWS_30000','FLOWS_FILES', 
                                      'MDDATA', 'ORACLE_OCM', 
                                      'XS$NULL', 'SPATIAL_CSW_ADMIN_USR', 
                                      'SPATIAL_WFS_ADMIN_USR', 'PUBLIC', 
                                      'WK_TEST','WKSYS', 'OUTLN')
               GROUP BY us.segment_name
             ) DATA)
       GROUP BY size_interval
       ORDER BY size_interval;

Output:

Fig 1: No. of tables by Bytes

Query 2: [Kilo Bytes] Number of all tables accessible to the current user in Oracle database by their size grouped into predefined intervals.

Bytes to kilobytes would be dividing by 1024. The divisions take you from bytes to kilobytes.

SELECT size_interval,
       count(*) AS no_of_tables
  FROM (SELECT DATA.segment_name table_name,
              CASE
               WHEN DATA.kilobytes> 1000000000
               THEN '1b Kilobytes (KB) and more'
               WHEN DATA.kilobytes> 1000000
               THEN '1m - 1b Kilobytes (KB)'
               WHEN DATA.kilobytes> 1000
               THEN '1k - 1m Kilobytes (KB)'
               WHEN DATA.kilobytes> 100
               THEN '100 - 1k Kilobytes (KB)'
               WHEN DATA.kilobytes> 10
               THEN '10 - 100 Kilobytes (KB)'
               ELSE '0 - 10 Kilobytes (KB)'
              END AS size_interval
        FROM (SELECT us.segment_name,
                     sum(us.bytes)/1024 kilobytes
                FROM sys.user_segments us,
                     sys.all_tables at
               WHERE at.table_name = us.segment_name
                 AND us.segment_type = 'TABLE'
                  -- excluding some Oracle maintained schemas 
                 AND AT.owner NOT IN ('ANONYMOUS','CTXSYS',
                                      'DBSNMP','EXFSYS', 
                                      'LBACSYS', 'MDSYS', 
                                      'MGMT_VIEW','OLAPSYS', 
                                      'OWBSYS','ORDPLUGINS', 
                                      'ORDSYS', 'SI_INFORMTN_SCHEMA', 
                                      'SYS','SYSMAN',
                                      'SYSTEM', 'TSMSYS',
                                      'DIP', 'WKPROXY',
                                      'WMSYS','XDB',
                                      'APEX_040000', 'APEX_PUBLIC_USER', 
                                      'FLOWS_30000','FLOWS_FILES', 
                                      'MDDATA', 'ORACLE_OCM', 
                                      'XS$NULL', 'SPATIAL_CSW_ADMIN_USR', 
                                      'SPATIAL_WFS_ADMIN_USR', 'PUBLIC', 
                                      'WK_TEST','WKSYS', 'OUTLN')
               GROUP BY us.segment_name
             ) DATA)
       GROUP BY size_interval
       ORDER BY size_interval;

Output:
Fig 2: No. of tables by Kilobytes (KB)

Query 3: [Megabytes] Number of all tables accessible to the current user in Oracle database by their size grouped into predefined intervals.

Bytes to megabytes would be dividing by 1024 two times. The divisions take you from bytes to kilobytes to megabytes.

SELECT size_interval,
       count(*) AS no_of_tables
  FROM (SELECT DATA.segment_name table_name,
              CASE
               WHEN DATA.megabytes> 1000000000
               THEN '1b Megabytes (MB) and more'
               WHEN DATA.megabytes> 1000000
               THEN '1m - 1b Megabytes (MB)'
               WHEN DATA.megabytes> 1000
               THEN '1k - 1m Megabytes (MB)'
               WHEN DATA.megabytes> 100
               THEN '100 - 1k Megabytes (MB)'
               WHEN DATA.megabytes> 10
               THEN '10 - 100 Megabytes (MB)'
               ELSE '0 - 10 Megabytes (MB)'
              END AS size_interval
        FROM (SELECT us.segment_name,
                     sum(us.bytes)/1024/1024 megabytes
                FROM sys.user_segments us,
                     sys.all_tables at
               WHERE at.table_name = us.segment_name
                 AND us.segment_type = 'TABLE'
                  -- excluding some Oracle maintained schemas 
                 AND AT.owner NOT IN ('ANONYMOUS','CTXSYS',
                                      'DBSNMP','EXFSYS', 
                                      'LBACSYS', 'MDSYS', 
                                      'MGMT_VIEW','OLAPSYS', 
                                      'OWBSYS','ORDPLUGINS', 
                                      'ORDSYS', 'SI_INFORMTN_SCHEMA', 
                                      'SYS','SYSMAN',
                                      'SYSTEM', 'TSMSYS',
                                      'DIP', 'WKPROXY',
                                      'WMSYS','XDB',
                                      'APEX_040000', 'APEX_PUBLIC_USER', 
                                      'FLOWS_30000','FLOWS_FILES', 
                                      'MDDATA', 'ORACLE_OCM', 
                                      'XS$NULL', 'SPATIAL_CSW_ADMIN_USR', 
                                      'SPATIAL_WFS_ADMIN_USR', 'PUBLIC', 
                                      'WK_TEST','WKSYS', 'OUTLN')
               GROUP BY us.segment_name
             ) DATA)
       GROUP BY size_interval
       ORDER BY size_interval;

Output:
Fig 3: No. of tables by Megabytes (MB)

Query 4: [Gigabytes] Number of all tables accessible to the current user in Oracle database by their size grouped into predefined intervals.

Bytes to gigabytes would be dividing by 1024 three times. The divisions take you from bytes to kilobytes to megabytes to gigabytes.

SELECT size_interval,
       count(*) AS no_of_tables
  FROM (SELECT DATA.segment_name table_name,
              CASE
               WHEN DATA.gigabytes> 1000000000
               THEN '1b Gigabytes (GB) and more'
               WHEN DATA.gigabytes> 1000000
               THEN '1m - 1b Gigabytes(GB)'
               WHEN DATA.gigabytes> 1000
               THEN '1k - 1m Gigabytes (GB)'
               WHEN DATA.gigabytes> 100
               THEN '100 - 1k Gigabytes (GB)'
               WHEN DATA.gigabytes> 10
               THEN '10 - 100 Gigabytes (GB)'
               ELSE '0 - 10 Gigabytes (GB)'
              END AS size_interval
        FROM (SELECT us.segment_name,
                     sum(us.bytes)/1024/1024/1024 gigabytes
                FROM sys.user_segments us,
                     sys.all_tables at
               WHERE at.table_name = us.segment_name
                 AND us.segment_type = 'TABLE'
                  -- excluding some Oracle maintained schemas 
                 AND AT.owner NOT IN ('ANONYMOUS','CTXSYS',
                                      'DBSNMP','EXFSYS', 
                                      'LBACSYS', 'MDSYS', 
                                      'MGMT_VIEW','OLAPSYS', 
                                      'OWBSYS','ORDPLUGINS', 
                                      'ORDSYS', 'SI_INFORMTN_SCHEMA', 
                                      'SYS','SYSMAN',
                                      'SYSTEM', 'TSMSYS',
                                      'DIP', 'WKPROXY',
                                      'WMSYS','XDB',
                                      'APEX_040000', 'APEX_PUBLIC_USER', 
                                      'FLOWS_30000','FLOWS_FILES', 
                                      'MDDATA', 'ORACLE_OCM', 
                                      'XS$NULL', 'SPATIAL_CSW_ADMIN_USR', 
                                      'SPATIAL_WFS_ADMIN_USR', 'PUBLIC', 
                                      'WK_TEST','WKSYS', 'OUTLN')
               GROUP BY us.segment_name
             ) DATA)
       GROUP BY size_interval
       ORDER BY size_interval;

Output:
Fig 4: No. of tables by Gigabytes (GB)

Query 5: [Terabytes] Number of all tables accessible to the current user in Oracle database by their size grouped into predefined intervals.

Bytes to gigabytes would be dividing by 1024 four times. The divisions take you from bytes to kilobytes to megabytes to gigabytes to terabytes.

SELECT size_interval,
       count(*) AS no_of_tables
  FROM (SELECT DATA.segment_name table_name,
              CASE
               WHEN DATA.terabytes> 1000000000
               THEN '1b Terabytes (TB) and more'
               WHEN DATA.terabytes> 1000000
               THEN '1m - 1b Terabytes (TB)'
               WHEN DATA.terabytes> 1000
               THEN '1k - 1m Terabytes (TB)'
               WHEN DATA.terabytes> 100
               THEN '100 - 1k Terabytes (TB)'
               WHEN DATA.terabytes> 10
               THEN '10 - 100 Terabytes (TB)'
               ELSE '0 - 10 Terabytes (TB)'
              END AS size_interval
        FROM (SELECT us.segment_name,
                     sum(us.bytes)/1024/1024/1024/1024 terabytes
                FROM sys.user_segments us,
                     sys.all_tables at
               WHERE at.table_name = us.segment_name
                 AND us.segment_type = 'TABLE'
                  -- excluding some Oracle maintained schemas 
                 AND AT.owner NOT IN ('ANONYMOUS','CTXSYS',
                                      'DBSNMP','EXFSYS', 
                                      'LBACSYS', 'MDSYS', 
                                      'MGMT_VIEW','OLAPSYS', 
                                      'OWBSYS','ORDPLUGINS', 
                                      'ORDSYS', 'SI_INFORMTN_SCHEMA', 
                                      'SYS','SYSMAN',
                                      'SYSTEM', 'TSMSYS',
                                      'DIP', 'WKPROXY',
                                      'WMSYS','XDB',
                                      'APEX_040000', 'APEX_PUBLIC_USER', 
                                      'FLOWS_30000','FLOWS_FILES', 
                                      'MDDATA', 'ORACLE_OCM', 
                                      'XS$NULL', 'SPATIAL_CSW_ADMIN_USR', 
                                      'SPATIAL_WFS_ADMIN_USR', 'PUBLIC', 
                                      'WK_TEST','WKSYS', 'OUTLN')
               GROUP BY us.segment_name
             ) DATA)
       GROUP BY size_interval
       ORDER BY size_interval;

Output:
Fig 5: No. of tables by Terabytes (TB)
Reference:

Happy APEXing!!!...

Comments

Post a Comment

Popular posts from this blog

Printing Page Numbers in RTF Template [Oracle BI Publisher]

Here I am giving an example to print the page numbers dynamically in the RTF (Rich Text Format) template. Step 1:  Go to page footer and copy and paste the below script. Page |  <?fo:page-number?>  of  <?fo:page-number-citation:xdofo:lastpage-joinseq?> <fo:page-number> :   This is the object, which is used to represent the current page-number. <?fo:page-number-citation:xdofo:lastpage-joinseq?> :  This is the syntax, which is used to represent the total number of pages. Step 2:  Load the XML and preview the result. Output: That's it. References: fo:page-number Printing Page Number Code in Oracle XMLP RTF Template

Oracle Application Express Views (APEX)

Application Express Views Search SELECT * FROM apex_dictionary WHERE column_id = 0; View Comment Parent View APEX_APPLICATIONS Applications defined in the current workspace or database user. APEX_WORKSPACES APEX_APPLICATION_ALL_AUTH All authorization schemes for all components by Application APEX_APPLICATIONS ...

Save Selected Interactive Grid Records into a Collection - Oracle APEX

Here I am giving an example to save selected interactive grid records into a oracle apex collection. Step 1: Create a new blank page. Note: Mine was page 20. You will need to update reference to " P20 " with your page number if it's different. Step 2: Create a new interactive grid report region to the page using below query. Set Static Id "EmpDetails" to the region. SELECT  *     FROM   ( SELECT  emp . empno ,                emp . ename ,                emp . JOB ,                dept . dname department ,                dept . loc  LOCATION ,                mgr . ename  ...