要求统计某用户的所有表分别有多少行?当然,可以一个一个表的select count(1) from tableName,其实还有很多办法:
1.用过程
新建一个表tableCount,用来存储结果。
新建一个过程sp_count。
执行过程sp_count:
OK!
1.用过程
新建一个表tableCount,用来存储结果。
create table tableCount(tableName varchar2(100) not null,colCount number(10) not null);
新建一个过程sp_count。
create or replace procedure sp_count is
cursor countTable is
select 'insert into tableCount select count(*),''' || table_name || ''' from ' || table_name || '' str
from user_tables;
v_str varchar2(200);
begin
open countTable ;
loop
fetch countTable
into v_str;
exit when countTable%notfound;
-- v_str:='insert into tableCount(num) select count(*) from PLAN_TABLE';
execute immediate v_str;
end loop;
close countTable;
end;
执行过程sp_count:
exec sp_count;
OK!