达梦数据库查询库中所有表的数据量
程序员文章站
2022-06-02 22:06:50
...
## 1 查询库中表的数据量
```
-- 1.创建临时表
-- create global temporary table test(tab_name varchar(30),row_num int) on commit preserve rows;
-- 2.执行语句 'DB'代表用户名
declare
count_rows int;
v_sql varchar(100);
begin
count_rows:=0;
for a in (select TABLE_NAME from dba_tables where owner='DB' and TABLESPACE_NAME<>'TEMP')
loop
v_sql:='select count(*) from DB.'||a.TABLE_NAME;
execute immediate v_sql into count_rows;
insert into test values(a.TABLE_NAME,count_rows);
end loop;
select * from test;
end;
```