-- 创建统计备分表
exec dbms_stats.create_stat_table(user,'mystat');
-- 创建测试表
create table t (id number, name varchar2(30));
begin
for i in 1 .. 10 loop
insert into t (id, name) values(i, 'Steven Jobs');
end loop;
commit;
end;
/
-- 修改日期格式
alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
-- 搜集统计信息
exec dbms_stats.gather_table_stats(user,'T',stattab=>'mystat',statid=>'S001');
-- 查询数据字典里的统计信息
select table_name, num_rows, last_analyzed from user_tables where table_name='T';
-- 查询mystat表,返回空
select statid, type, n1 num_rows, d1 last_analyzed
from mystat
where statid='S001' and type='T';
-- 插入5条数据,再次收集
insert into t select * from t where rownum<=5;
commit;
exec dbms_stats.gather_table_stats(user,'T',stattab=>'mystat',statid=>'S002');
-- 查询数据字典里的统计信息
select table_name, num_rows, last_analyzed from user_tables where table_name='T';
-- 查询mystat表,返回行数为10,即上次收集的统计
select statid, type, n1 num_rows, d1 last_analyzed
from mystat
where statid='S002' and type='T';
用dbms_stats的备份表,备份统计信息
最新推荐文章于 2025-05-30 09:44:44 发布