GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Tech FAQs  >  PL/SQL

 Print  |  
Question:  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).

Answer: Database has 100 tables and some of the tables dont have any data. I want to pullout those table names from database in Oracle.


September 09, 2007 07:09:16 #1
 hemangi.savaliya   Member Since: Visitor    Total Comments: N/A 

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;

     

 

Back To Question