We help IT Professionals succeed at work.
Get Started

Add sequence number to a query.

Kamal Agnihotri
on
107 Views
Last Modified: 2016-01-19
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
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2012
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE