工作中,我们时常统计某个模式下有哪些表,表中有多少条记录,如果每张表去统计,工作量会非常的大。介绍一种简单方便的统计方法:
1.创建一张临时表:
create global temporary table test(tab_name varchar(30),row_num int) on commit preserve rows;
2.执行语句体:
declare
count_rows int;
v_sql varchar(100);
begin
count_rows:=0;
for a in (select TABLE_NAME from dba_tables where owner='DMHR' and TABLESPACE_NAME <>'TEMP')
loop
v_sql:='select count(*) from DMHR.'||a.TABLE_NAME;
execute immediate v_sql intocount_rows;
insert into tes tvalues(a.TABLE_NAME,count_rows);
end loop;
select * from test;
end;
/
实际使用中把DMHR替换成对应的模式名。