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)
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)
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:
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:
Reference:
Thanks Sameer
ReplyDeleteDiscover the best quality IT Products to suit your hardware accessories. You can Purchase IT Works Products!
ReplyDelete