Oracle-查询用户下所有表的数据量

一般我们通过count()语句就可以查询单张标的数据量,但是遇到很多情况,查询多张表,数据量特别大的时候,就比较慢,耽搁时间,毕竟开发的时间还是很宝贵的;

也有通过下面的SQL去查询数据量,但不知道为什么,有的库可以查到,有的直接返回空,或许是权限问题吧,哪位大神可以解惑。

select t.table_name,t.num_rows from user_tables t

遇事,不得不创建个函数来查询,具体如下:

create or replace function count_table_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;
-- Oracle 查询用户下所有表的记录数
end;

接下来,只需要简单的查询就可以查询了:

select table_name, count_table_rows(table_name) nrows
from user_tables
where table_name like 'AAA%'
order by nrows desc

当然也可以进行sum()汇总等写法,可以自由发挥啦!

相关推荐

  1. Oracle-查询用户所有数据

    2024-01-18 23:56:03       60 阅读
  2. oracle 查询分隔符分隔开所有数据

    2024-01-18 23:56:03       27 阅读
  3. 工作随记:oracle重建一张1T数据

    2024-01-18 23:56:03       47 阅读
  4. Oracle查询字段所属及其应用场景详解

    2024-01-18 23:56:03       32 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-18 23:56:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-18 23:56:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-18 23:56:03       82 阅读
  4. Python语言-面向对象

    2024-01-18 23:56:03       91 阅读

热门阅读

  1. Go语言网络轮询器

    2024-01-18 23:56:03       54 阅读
  2. 24校招,阿里巴巴测试开发工程师二面

    2024-01-18 23:56:03       42 阅读
  3. vue3自定义指令

    2024-01-18 23:56:03       70 阅读
  4. 智慧校园大数据云平台介绍

    2024-01-18 23:56:03       55 阅读
  5. 支付功能的实现

    2024-01-18 23:56:03       58 阅读
  6. RPM命令详解2---查询&验证

    2024-01-18 23:56:03       51 阅读