Oracle查询数据库中当前用户每个表的数据条数

Oracle查询数据库中当前用户每个表的数据条数

bash 复制代码
select t.table_name,t.num_rows from user_tables t

一般情况下这条语句就可查出想要结果

如果不行

请执行以下脚本

bash 复制代码
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;

写了此方法以后在sql语句中调用即可

bash 复制代码
select table_name, count_rows(table_name) nrows from user_tables ;
相关推荐
v(kaic_kaic)4 小时前
基于STM32热力二级管网远程监控系统设计(论文+源码)_kaic
android·数据库·学习·mongodb·微信·目标跟踪·小程序
ONE_one_plus4 小时前
1分钟理解脏读、幻读与不可重复读
数据库·mysql
非法小恋5 小时前
华为GaussDB数据库之Yukon安装与使用
数据库·gaussdb
m0_689087075 小时前
9.28 Qt界面
开发语言·数据库·qt
大龙@、5 小时前
MongoDB简介
数据库·mongodb
codelife3215 小时前
MongoDB 入门及实践
数据库·mongodb
42fourtytoo6 小时前
SQL总结
数据库·python·sql·计算机网络·安全·网络安全
健康平安的活着6 小时前
redis 中IO多路复用与Epoll函数
网络·数据库·redis