这篇文章主要讲解了“Oracle数据库的表有多大”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Oracle数据库的表有多大”吧!
1. 查看一般表的大小
select segment_name,segment_type,bytes/1024/1024 M from dba_segments where segment_name='SETTINGS$' and segment_type='TABLE';
2. 查看带有LOB字段的表的大小
LOB字段是有额外的专门区域存放,查看带有LOB字段的表的大小比较复杂,分为了普通的字段大小,LOB字段大小,LOB索引字段大小,三个部分。
SELECT (SELECT SUM(S.BYTES/1024/1024/1024) -- The Table Segment size FROM DBA_SEGMENTS S WHERE S.OWNER = UPPER('表的owner') AND (S.SEGMENT_NAME = UPPER('表名'))) + (SELECT SUM(S.BYTES/1024/1024/1024) -- The Lob Segment Size FROM DBA_SEGMENTS S, DBA_LOBS L WHERE S.OWNER = UPPER('表的owner') AND (L.SEGMENT_NAME = S.SEGMENT_NAME AND L.TABLE_NAME = UPPER('表名') AND L.OWNER = UPPER('表的owner'))) + (SELECT SUM(S.BYTES/1024/1024/1024) -- The Lob Index size FROM DBA_SEGMENTS S, DBA_INDEXES I WHERE S.OWNER = UPPER('表的owner') AND (I. INDEX_NAME = S.SEGMENT_NAME AND I.TABLE_NAME = UPPER('表名') AND INDEX_TYPE= 'LOB' AND I.OWNER = UPPER('表的owner'))) "TOTAL TABLE SIZE" FROM DUAL;
详细介绍内容可以查看Doc ID 118531.1
如果想查看这个库里有多少个带有LOB字段的表呢?通过dba_lobs可以查看。
例如:select distinct owner,table_name from dba_lobs where owner in ('***',’***’);
如果搜出几百个几千个LOB字段的表,一个个查大小,会很久…………
怎么把带有LOB字段的表一次性列出来呢?
先创建一个临时表:
SQL> create table candidates (owner varchar2(30),segment_name varchar2(81));
再把上面查出来的带有LOB字段的表插入进临时表里:
SQL> insert into candidates values ('owner','table_name');
然后利用游标:
SQL> set serveroutput on SQL> declare cursor cur_temp is select owner, segment_name from candidates; v_owner varchar2(30); v_segment_name varchar2(81); v_total_table_size number; begin open cur_temp; fetch cur_temp into v_owner,v_segment_name; while cur_temp%FOUND loop SELECT ( SELECT nvl(SUM(S.BYTES/1024/1024/1024),0) FROM DBA_SEGMENTS S WHERE S.OWNER = UPPER(v_owner) AND (S.SEGMENT_NAME = UPPER(v_segment_name))) + (SELECT nvl(SUM(S.BYTES/1024/1024/1024),0) FROM DBA_SEGMENTS S, DBA_LOBS L WHERE S.OWNER = UPPER(v_owner) AND (L.SEGMENT_NAME = S.SEGMENT_NAME AND L.TABLE_NAME = UPPER(v_segment_name) AND L.OWNER = UPPER(v_owner)) ) + (SELECT nvl(SUM(S.BYTES/1024/1024/1024),0) FROM DBA_SEGMENTS S, DBA_INDEXES I WHERE S.OWNER = UPPER(v_owner) AND (I.INDEX_NAME = S.SEGMENT_NAME AND I.TABLE_NAME = UPPER(v_segment_name) AND INDEX_TYPE= 'LOB' AND I.OWNER = UPPER(v_owner)) ) "TOTAL TABLE SIZE" into v_total_table_size FROM DUAL; DBMS_OUTPUT.PUT_LINE('Table '||v_segment_name||': '||v_total_table_size); fetch cur_temp into v_owner,v_segment_name; end loop; end; /
就会把带有LOB字段的表大小都列出来了。
一般查大小就只查dba_segments了,查LOB的时候好像不多。偶尔查一下就用步骤2的方法就行,也是官方提供的。
感谢各位的阅读,以上就是“Oracle数据库的表有多大”的内容了,经过本文的学习后,相信大家对Oracle数据库的表有多大这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!