需求:查询Oracle当前用户下,所有数据表的总条数
方法:存储过程
右键点击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;