已索引
set serveroutput on
DECLARE
ub NUMBER;
ab NUMBER;
cl sys.create_table_cost_columns;
BEGIN
cl := sys.create_table_cost_columns(
sys.create_table_cost_colinfo('NUMBER',10),
sys.create_table_cost_colinfo('VARCHAR2',30),
sys.create_table_cost_colinfo('VARCHAR2',30),
sys.create_table_cost_colinfo('DATE',NULL));
DBMS_SPACE.CREATE_TABLE_COST('SYSTEM',cl,100000,0,ub,ab);
DBMS_OUTPUT.PUT_LINE('Used Bytes: ' || TO_CHAR(ub));
DBMS_OUTPUT.PUT_LINE('Alloc Bytes: ' || TO_CHAR(ab));
END;
/
说明:
- 可以在 Oracle 官方文档中找到该范例;
- 根据自己的表结构修改 cl 的值;
- SYSTEM 是表所在表空间,根据实际情况修改;
- 100000 是表的行数据;
- 0 是 pct_free 的值,根据表的实际情况修改;
ub,ab 分别表示 used_bytes,alloc_bytes:
- The used_bytes represent the actual bytes used by the data. This includes the overhead due to the block metadata, pctfree etc.
- The alloc_bytes represent the size of the table when it is created in the tablespace. This takes into account, the size of the extents in the tablespace and tablespace extent management properties.
- 虽然这是 Oracle 的存储过程,但是也可以用来对其它类型数据库的表大小进行一个大致的估算。