GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Tech FAQs  >  PL/SQL
Go To First  |  Previous Question  |  Next Question 
 PL/SQL  |  Question 105 of 166    Print  
How to write a query or procedure or function to retrieve all the tables from database where the table dont have any data (no rows).
Database has 100 tables and some of the tables dont have any data. I want to pullout those table names from database in Oracle.


  
Total Answers and Comments: 3 Last Update: June 04, 2008     Asked by: Robert 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: ravgopal
 
Analyze and perform statistics on whole schema.  This will populate the statistics details about each table.  You can pull NUM_ROWS column from all_tables to check whether it contains zero.

step1: exec dbms_stats.gather_database_stats;

Step2 : select table_name from all_tables where num_rows=0;

Above answer was rated as good by the following members:
sr_2407
September 26, 2007 07:09:16   #1  
hemangi.savaliya        

RE: How to write a query or procedure or function to r...

DECLARE
vtname VARCHAR2(100);
CURSOR cur_tablename IS
SELECT tname
FROM tab;
BEGIN
OPEN cur_tablename;

FOR i IN
1 .. 100
LOOP
FETCH cur_tablename
INTO vtname;
EXIT WHEN cur_tablename NOTFOUND;
dbms_output.put_line(
' table name' || vtname);
BEGIN
EXECUTE IMMEDIATE
' select 1 from ' || vtname; --||' where rownum<2';
EXCEPTION
WHEN no_data_found THEN

dbms_output.put_line(
' doesn''t have data' || vtname);
END;
END LOOP;

CLOSE cur_tablename;

END;


 
Is this answer useful? Yes | No
October 10, 2007 13:13:27   #2  
ravgopal Member Since: October 2007   Contribution: 7    

RE: How to write a query or procedure or function to r...
Analyze and perform statistics on whole schema. This will populate the statistics details about each table. You can pull NUM_ROWS column from all_tables to check whether it contains zero.

step1: exec dbms_stats.gather_database_stats;

Step2 : select table_name from all_tables where num_rows 0;

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
June 04, 2008 01:07:21   #3  
sr_2407 Member Since: February 2008   Contribution: 4    

RE: How to write a query or procedure or function to retrieve all the tables from database where the table dont have any data (no rows).
select table_name num_rows from user_tables
where num_rows 0

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape