Go Premium for a chance to win a PS4. Enter to Win


PL/SQL for 2 looping structure

Posted on 2011-09-21
Medium Priority
Last Modified: 2012-05-12
I want to get the name of the tables belonging to a user and then find the record count count(*) for that table in a 2nd loop and insert table_name, count(*) into a static table
Question by:Greens8301
  • 3
  • 2

Author Comment

ID: 36577112

For ueach user in (usr1,usr2,usr3 ...)
loop 1
Get the names of tables belonging to the user
loo 2
get the total number of records for each table that user owns

INSERT into a static table (table_name, recCNT)

I need a PL/SQL code to do this

LVL 78

Accepted Solution

slightwv (䄆 Netminder) earned 2000 total points
ID: 36577538
You can do in in a single sql statement.

Take the following solution, add the table_name, an insert into table (select ...), change the view from user_tables to dba_users and add a: where username in ('A','B');
And you should be good to go.

LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36580723
I remembered you need to remove the SUM call in that code.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Expert Comment

ID: 36713243

insert into tab_resume (tab_name ,tab_count)
select table_name ,num_rows
from dba_tables
where owner = 'NAME_USER'
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36713473
Num_rows is an estimate based off statistics.  You need to be aware the number might be off.

Author Closing Comment

ID: 37033417

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Suggested Courses

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question