oracle查询表以及表上索引占用空间大小

var t_owner varchar2(30);
var t_name varchar2(30);
exec :t_owner := 'scott';
exec :t_name := 'emp';
select t1.owner || '.' || t1.table_name table_name,
       t1.tab_gb + nvl(t2.idx_gb, 0) + nvl(t3.lob_gb, 0) total_gb,
       t1.tab_gb,
       nvl(t2.idx_gb, 0) idx_gb,
       nvl(t3.lob_gb, 0) lob_gb
  from (select owner,
               segment_name table_name,
               round(sum(bytes) / 1024 / 1024 / 1024, 4) TAB_GB  --表对象占用空间
          from dba_segments
         where owner = upper(:t_owner)
           and segment_name = upper(:t_name)
         group by owner, segment_name) t1, 
       (select round(sum(bytes) / 1024 / 1024 / 1024, 4) IDX_GB  --表上索引对象占用空间
          from dba_segments
         where owner || segment_name in
               (select owner || index_name
                  from dba_indexes
                 where table_owner = upper(:t_owner)
                   and table_name = upper(:t_name))) t2, 
       (select round(sum(bytes) / 1024 / 1024 / 1024, 4) LOB_GB --表上大字段对象占用空间
          from dba_segments
         where owner || segment_name in
               (select owner || segment_name
                  from dba_lobs
                 where owner = upper(:t_owner)
                   and table_name = upper(:t_name))) t3;

你可能感兴趣的:(Oracle数据库)