Experts,
There are 203 Tables in my Schema. The code below gives me the count of number of records in each table.
declare
v_rowcnt integer;
begin
for t in (select table_name from user_tables order by 1) loop
execute immediate 'select count(*) from ' || t.table_name into v_rowcnt;
dbms_output.put_line(rpad(t.table_name,40,'.') || v_rowcnt);
end loop;
end;
/
--############################################
The first few lines of the output look like this:
ACCOUNT.................................1
AD......................................7
AD_AGE_STATED...........................6
AD_BODY.................................7
AD_CATEGORY.............................1
AD_LOCATION_STATED......................7
AD_LOCATION_WEBSITE.....................7
AD_NAME_ADVERTISED......................1
--#####################
I would like the output to look below. Add another column to the right (First Column) to tell the sequence number of the table. How do I modify the script above to get the desired result.
1 ACCOUNT.................................1
2 AD......................................7
3 AD_AGE_STATED...........................6
4 AD_BODY.................................7
5 AD_CATEGORY.............................1
6 AD_LOCATION_STATED......................7
7 AD_LOCATION_WEBSITE.....................7
8 AD_NAME_ADVERTISED......................1
With your guidance, the code below works. Would you written it any differently.
--########################
declare
v_row integer := 0;
v_rowcnt integer;
begin
for t in (select table_name from user_tables order by 1) loop
v_row := v_row + 1;
execute immediate 'select count(*) from ' || t.table_name into v_rowcnt;
dbms_output.put_line (rpad(v_row, 5, ' ') || (rpad(t.table_name,40,'.')
end loop;
end;
/