一、创建测试表
SQL> Create Table T As Select * From Dba_Objects;
Table created
二、创建索引
SQL> Create Index t_Ind On t (Object_Id);
Index created
三、收集统计信息
SQL> exec dbms_stats.gather_table_stats(user,'T',cascade=>true);
PL/SQL procedure successfully completed
四、计算平均行长度
SQL> Select t.Avg_Row_Len From User_Tables t Where Table_Name = 'T';
AVG_ROW_LEN
-----------
97
五、计算表占用的空间
SQL> select count(*) * 97 from t ;
COUNT(*)*97
-----------
7038902
五、计算索引和表的百分比
SQL> Select Sn.segment_Name,Sn.segment_Type,Sn.bytes From User_Segments Sn Where Segment_Name in ('T','T_IND');
SEGMENT_NAME SEGMENT_TYPE BYTES
-------------------------------------------------------------------------------- ------------------ ----------
T TABLE 9437184
T_IND INDEX 2097152
SQL> select trunc(2097152/9437184 * 100) from dual;
TRUNC(2097152/9437184*100)
--------------------------
22
六、表的总使用容量
SQL> select (97 * count(*)* (1 + 22)) totalspace from t;
TOTALSPACE
----------
161894746
阅读(2388) | 评论(0) | 转发(0) |