当前位置:   article > 正文

查询Oracle当前用户下,所有数据表的总条数_oracle 查询数据库用户库表条数

oracle 查询数据库用户库表条数

1. 需求

查询Oracle当前用户下,所有数据表的总条数

2.方法

方法1:存储过程

(文末有方法2,一个SQL也可轻松搞定!)

3. 操作(方法1:存储过程)

3.1 新建

右键点击Procedures,点击New

在这里插入图片描述

点击OK
在这里插入图片描述

把存储过程写进去,然后点击编译运行:

在这里插入图片描述

create or replace procedure tables_count is
 
  t_count   number(10);
  t_str VARCHAR2(500);
  t_total number(2) := 0 ;
  cursor t_tables is select table_name  table_name from user_tables;
begin 
  for t_row in t_tables loop
    begin
      dbms_output.enable (buffer_size => null);
    t_str := 'select count(*) from '|| t_row.table_name;
    execute immediate t_str into t_count;
    t_total:=t_total+t_count;
     
    dbms_output.put_line( t_row.table_name || '=' || to_char(t_count)); 
    end;    
  end loop;
  dbms_output.put_line('');
  dbms_output.put_line('此用户下总数据条数一共是' || t_total || '条');
end tables_count;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

3.2 执行

3.2.1 方法一
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

方法2

点击File --> New --> Test Window

在这里插入图片描述
写入刚刚新增的存储过程

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

方法2:SQL

select sum(t.NUM_ROWS) FROM USER_TABLES T;

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小惠珠哦/article/detail/752508
推荐阅读
相关标签
  

闽ICP备14008679号