使用dbms_stats列出没有统计信息的对象!

利用dbms_stats的procedure gather_schema_stats 和gather_database_stats通过使用参数options 和objlist可以列出那些没有统计信息或者统计信息stale的对象。

[@more@]

其中options的值可以是:

ValueMeaning

GATHER STALE

Gathers statistics on tables with stale statistics.

GATHER

Gathers statistics on all tables. (default)

GATHER EMPTY

Gathers statistics only on tables without statistics.

LIST STALE

Creates a list of tables with stale statistics.

LIST EMPTY

Creates a list of tables that do not have statistics.

GATHER AUTO

Gathers all the statistics for the objects of a specific schema (or database with DBMS_STATS.GATHER_DATABASE_STATS()) that are not up-to-date.

The objlist parameter identifies an output parameter for the LIST STALE and LIST EMPTY options. The objlist parameter is of type DBMS_STATS.OBJECTTAB.

--===============================================

SQL> edit
已写入 file afiedt.buf

1 declare
2 v_obj dbms_stats.objecttab;
3 begin
4 dbms_stats.gather_schema_stats
5 (OWNNAME=>'XYS',OPTIONS=>'LIST EMPTY',OBJLIST=>v_obj );
6 for i in 1 .. v_obj .count
7 loop
8 dbms_output.put_line( v_obj (i).ownname );
9 dbms_output.put_line( v_obj (i).objType );
10 dbms_output.put_line( v_obj (i).objName );
11 dbms_output.put_line( v_obj (i).PartName );
12 dbms_output.put_line( v_obj (i).subPartName );
13 dbms_output.put_line
14 ( '-------------------------' );
15 end loop;
16* end;
SQL> /
XYS
TABLE
MY_STAT_TAB
-------------------------
XYS
TABLE
T1
-------------------------
XYS
TABLE
TEST
-------------------------
XYS
TABLE
TEST1
-------------------------
XYS
TABLE
TT1
-------------------------
XYS
INDEX
IDX_T1
-------------------------
XYS
INDEX
MY_STAT_TAB
-------------------------

PL/SQL 过程已成功完成。

SQL> select table_name,num_rows,blocks,avg_row_len from user_tables;

TABLE_NAME NUM_ROWS BLOCKS AVG_ROW_LEN
------------------------------ ---------- ---------- -----------
T1
TEST
TEST1
TT1
TT 5 5 8
MY_STAT_TAB

已选择6行。

SQL> select index_name,blevel,leaf_blocks,clustering_factor from user_indexes;

INDEX_NAME BLEVEL LEAF_BLOCKS CLUSTERING_FACTOR
------------------------------ ---------- ----------- -----------------
IDX_TT 0 1 1
SYS_IL0000016783C00026$$
MY_STAT_TAB
IDX_T1

SQL>

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/19602/viewspace-1002654/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/19602/viewspace-1002654/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值