zoukankan      html  css  js  c++  java
  • Oracle查询数据库中所有表的记录数

    方法一:
    首先建立一个计算函数
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    create or replace function count_rows(table_name in varchar2,
                                  owner in varchar2 default null)
    return number
    authid current_user
    IS
       num_rows number;
       stmt varchar2(2000);
    begin
       if owner is null then
          stmt := 'select count(*) from "'||table_name||'"';
       else
          stmt := 'select count(*) from "'||owner||'"."'||table_name||'"';
       end if;
       execute immediate stmt into num_rows;
       return num_rows;
    end;

    然后通过计算函数进行统计
    select table_name, count_rows(table_name) nrows from user_tables
    获取要统计的值
    方法二:
    select t.table_name,t.num_rows from user_tables t
    查看记录数,但是num_rows存储的是上次分析后的值,不准确,要使用该方法,必须分析后才可以试用
    完成的语句为

    declare
    v_tName varchar(50);
    v_sqlanalyze varchar(500);
    v_num number;
    v_sql varchar(500);
    cursor c1
    is
    select table_name from user_tables;
    begin
    open c1;
    loop
    fetch c1 into v_tName;
    if c1%found then

    v_sqlanalyze :='analyze table '||v_tName||' estimate statistics';
    execute immediate v_sqlanalyze;
    v_sql := 'select NUM_ROWS from user_tables where table_name =upper('''||v_tName||''')';

    execute immediate v_sql into v_num;
    dbms_output.put_line('表名: '||v_tName||' 行数: '||v_num);
    else
    exit;
    end if;
    end loop;
    end;
  • 相关阅读:
    FastAdmin CMS 插件下载
    使用 Python 连接到 PADS Layout
    Javascript undefined 和 null
    反馈给又拍云需要以下信息
    Web前端性能优化之图片优化
    nodejs--实现跨域抓取数据
    HTML6 展望
    cSS3 伪类:nth-child 的使用方法
    css3中的几何图形shape研究
    iScroll5 API速查随记
  • 原文地址:https://www.cnblogs.com/langtianya/p/6526415.html
Copyright © 2011-2022 走看看