您的位置:首页 > 数据库 > Oracle

Oracle脚本获得统计信息

2013-07-29 10:39 393 查看
以下脚本可以获取某张表的统计信息,觉得很好,在此记下。

声明:脚本来自《Pro Oracle SQL》一书,st-all.sql

简单演示:

luocs@MAA> select * from tab;

TNAME TABTYPE CLUSTERID
------------------------------------------------------------ -------------- ----------
T1 TABLE

sys@MAA> @st-all
Enter the owner name: luocs
Enter the table name: t1
old 2: v_owner varchar2(30) := upper('&p_owner');
new 2: v_owner varchar2(30) := upper('luocs');
old 3: v_table varchar2(30) := upper('&p_table');
new 3: v_table varchar2(30) := upper('t1');
===================================================================================================================================
TABLE STATISTICS
===================================================================================================================================
Owner : luocs
Table name : t1
Tablespace : users
Cluster name :
Partitioned : no
Last analyzed : 11/06/2012 22:00:11
Sample size : 22671
Degree : 1
IOT Type :
IOT name :
# Rows : 22671
# Blocks : 320
Empty Blocks : 0
Avg Space : 0
Avg Row Length: 92
Monitoring? : yes
old 2: v_owner varchar2(30) := upper('&p_owner');
new 2: v_owner varchar2(30) := upper('luocs');
old 3: v_table varchar2(30) := upper('&p_table');
new 3: v_table varchar2(30) := upper('t1');

===================================================================================================================================
COLUMN STATISTICS
===================================================================================================================================
Name Analyzed Null? NDV Density # Nulls # Buckets Sample AvgLen Lo-Hi Values
===================================================================================================================================
created 11/06/2012 22:00:10 Y 764 .001309 0 1 22671 8 08/22/2012 18:44:29 | 11/06/2012 11:33:50
data_object_id 11/06/2012 22:00:10 Y 7675 .000130 14959 1 7712 3 0 | 23033
edition_name 11/06/2012 22:00:10 Y 0 .000000 22671 0 0 |
generated 11/06/2012 22:00:10 Y 2 .500000 0 1 22671 2 N | Y
last_ddl_time 11/06/2012 22:00:10 Y 813 .001230 0 1 22671 8 08/22/2012 18:44:29 | 11/06/2012 11:33:50
namespace 11/06/2012 22:00:10 Y 17 .058824 0 1 22671 3 1 | 64
object_id 11/06/2012 22:00:10 Y 22671 .000044 0 1 22671 5 2 | 23033
object_name 11/06/2012 22:00:10 Y 18242 .000055 0 1 22671 21 ABSPATH | xdb-log13_TAB$xd
object_type 11/06/2012 22:00:10 Y 40 .025000 0 1 22671 7 CLUSTER | XML SCHEMA
owner 11/06/2012 22:00:10 Y 14 .071429 0 1 22671 7 APEX_030200 | XDB
secondary 11/06/2012 22:00:10 Y 2 .500000 0 1 22671 2 N | Y
status 11/06/2012 22:00:10 Y 1 1.000000 0 1 22671 6 VALID | VALID
subobject_name 11/06/2012 22:00:10 Y 83 .012048 22441 1 230 2 P0 | WRH$_WAITST_670567865_0
temporary 11/06/2012 22:00:10 Y 2 .500000 0 1 22671 2 N | Y
timestamp 11/06/2012 22:00:10 Y 831 .001203 0 1 22671 20 1997-04-12:12:59:00 | 2012-11-06:11:33:50

===================================================================================================================================
INDEX INFORMATION
===================================================================================================================================

Index Name BLevel Leaf Blks # Rows Distinct Keys Avg Lf/Blks/Key Avg Dt/Blks/Key Clustering Factor Sample Size Uniq? Type Status Deg Part? Vis? Last Analyzed
------------------------------------------------------------ ------- --------------- --------------- --------------- --------------- --------------- ----------------- --------------- ----- -------- -------- --- ----- ---- -------------------
INX_ID 1 50 22671 22671 1 1 370 22671 NO NORM VALID 1 NO . 11/06/2012 22:00:12

Index Name Pos# Order Column Name
------------------------------------------------------------ ---------- ----- ------------------------------

inx_id 1 ASC object_id

sys@MAA> exec dbms_stats.gather_table_stats('LUOCS','T1',cascade=>true);

sys@MAA> @st-all
Enter the owner name: luocs
Enter the table name: t1
===================================================================================================================================
TABLE STATISTICS
===================================================================================================================================
Owner : luocs
Table name : t1
Tablespace : users
Cluster name :
Partitioned : no
Last analyzed : 01/09/2013 18:17:50
Sample size : 22671
Degree : 1
IOT Type :
IOT name :
# Rows : 22671
# Blocks : 320
Empty Blocks : 0
Avg Space : 0
Avg Row Length: 92
Monitoring? : yes

===================================================================================================================================
COLUMN STATISTICS
===================================================================================================================================
Name Analyzed Null? NDV Density # Nulls # Buckets Sample AvgLen Lo-Hi Values
===================================================================================================================================
created 01/09/2013 18:17:50 Y 764 .001309 0 1 22671 8 08/22/2012 18:44:29 | 11/06/2012 11:33:50
data_object_id 01/09/2013 18:17:50 Y 7675 .000130 14959 1 7712 3 0 | 23033
edition_name 01/09/2013 18:17:50 Y 0 .000000 22671 0 0 |
generated 01/09/2013 18:17:50 Y 2 .500000 0 1 22671 2 N | Y
last_ddl_time 01/09/2013 18:17:50 Y 813 .001230 0 1 22671 8 08/22/2012 18:44:29 | 11/06/2012 11:33:50
namespace 01/09/2013 18:17:50 Y 17 .058824 0 1 22671 3 1 | 64
object_id 01/09/2013 18:17:50 Y 22671 .000044 0 1 22671 5 2 | 23033
object_name 01/09/2013 18:17:50 Y 18242 .000055 0 1 22671 21 ABSPATH | xdb-log13_TAB$xd
object_type 01/09/2013 18:17:50 Y 40 .025000 0 1 22671 7 CLUSTER | XML SCHEMA
owner 01/09/2013 18:17:50 Y 14 .071429 0 1 22671 7 APEX_030200 | XDB
secondary 01/09/2013 18:17:50 Y 2 .500000 0 1 22671 2 N | Y
status 01/09/2013 18:17:50 Y 1 1.000000 0 1 22671 6 VALID | VALID
subobject_name 01/09/2013 18:17:50 Y 83 .012048 22441 1 230 2 P0 | WRH$_WAITST_670567865_0
temporary 01/09/2013 18:17:50 Y 2 .500000 0 1 22671 2 N | Y
timestamp 01/09/2013 18:17:50 Y 831 .001203 0 1 22671 20 1997-04-12:12:59:00 | 2012-11-06:11:33:50

===================================================================================================================================
INDEX INFORMATION
===================================================================================================================================

Index Name BLevel Leaf Blks # Rows Distinct Keys Avg Lf/Blks/Key Avg Dt/Blks/Key Clustering Factor Sample Size Uniq? Type Status Deg Part? Vis? Last Analyzed
------------------------------------------------------------ ------- --------------- --------------- --------------- --------------- --------------- ----------------- --------------- ----- -------- -------- --- ----- ---- -------------------
INX_ID 1 50 22671 22671 1 1 370 22671 NO NORM VALID 1 NO . 01/09/2013 18:17:50

Index Name Pos# Order Column Name
------------------------------------------------------------ ---------- ----- ------------------------------
inx_id 1 ASC object_id

oracle视频教程请关注:http://u.youku.com/user_video/id_UMzAzMjkxMjE2.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息