你好,游客 登录 注册 搜索
背景:
阅读新闻

Oracle 查找数据库中有记录的表

[日期:2011-02-02] 来源:Linux社区  作者:qidian10 [字体:大 中 小]

通过执行select NUM_ROWS,table_name from user_tables where NUM_ROWS>0,是可以达到效果的。

但是:有时候数据是不准的,原因是执行该查询的时候要先对表进行分析。

分析表的语法为:analyze table table_name compute statistics;

如何批量对表进行分析呢?

1、存储过程+游标,循环,OK没有问题,但是有点麻烦。

create or replace procedure Pro_AnalyzeTables is
cursor cur_tab is
select table_name from user_tables;
record_cur_tab cur_tab%rowtype;
begin
delete from DataTables;
open cur_tab;
loop
fetch cur_tab into record_cur_tab;
exit when cur_tab%notfound;
execute immediate 'analyze table '||record_cur_tab.table_name||' compute statistics';
end loop;
insert into DataTables (select Table_name,NUM_Rows from user_tables where NUM_ROWS>0);
end Pro_AnalyzeTables;
2、Oracle中可以将结果输出到文件,那么可以利用这个搞他一下

      方法如下:
     
spool DataTables.sql;(这里你可以写路径,例如,I:\DataTable.sql,将会将数据写入到这个文件)
      select 'analyze table '||table_name||' compute statistics;' from user_tables;
      spool off;
      @DataTables.sql;
//执行该文件

      OK,这样对数据库该用户名下的所有表就分析完毕了,那么下一步就可以执行select NUM_ROWS,table_name from user_tables where NUM_ROWS>0
linux
相关资讯       Oracle教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款