Solved

SQL to check if the column is blank in multiple tables

Posted on 2014-01-31
6
193 Views
Last Modified: 2014-12-06
I have a SQL which results , the number of tables which uses EMAIl ID field, I have more than 60 tables which uses that EMAILID field. I want to find out how many of those 60 tables have values stored in EMAILID field and how many of them are blank

select table_name, num_rows from dba_tables
  where table_name in (SELECT DISTINCT  A.RECNAME FROM  TABLE1 A,TABLE2 B
WHERE
A.TAB_NAME = B.TAB_NAME

AND (A.FIELDNAME  = 'EMAILID' OR A.FIELDNAME = 'URL'))
AND NUM_ROWS > 0;


Table1 store all information related to Record & fields , what are the fields associated to each table. Table2 stores the record definition.
0
Comment
Question by:rsj1977
  • 2
6 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 39825561
First:
num_rows from dba_tables

num_rows isn't necessarily accurate.  It is based on the table statistics.



Not sure why you are storing table names in another table.

To get what I think you are after, you really don't need to.

Below is a test case based on what I think your requirements are.

If it isn't quite right, please ad to it with additional tables, columns of data and explain why you are add it and I'll try to tweak it.

drop table tab1 purge;
drop table tab2 purge;
drop table tab3 purge;

create table tab1(emailid char(1));
create table tab2(emailid char(1));
create table tab3(emailid char(1));
create table tab4(notanemail char(1));


insert into tab1 values('a');
insert into tab1 values('b');
insert into tab2 values('a');
insert into tab2 values(null);
insert into tab3 values('a');
insert into tab3 values(null);
insert into tab3 values(null);
insert into tab3 values(null);
insert into tab4 values(null);
commit;

SELECT table_name, column_name,
       TO_NUMBER(
           EXTRACTVALUE(
               xmltype(
                   DBMS_XMLGEN.
                    getxml(
                          'select count(*) X from '
                       || table_name
                       || ' where '
                       || column_name
                       || ' is null'
                   )
               ),
               '/ROWSET/ROW/X'
           )
       )
           COUNT
FROM user_tab_cols
where column_name='EMAILID';

Open in new window

0
 
LVL 31

Expert Comment

by:awking00
ID: 39826517
Are you trying to get the number of tables that have an email or url field where any values are blank or where all values are blank?
0
 

Author Comment

by:rsj1977
ID: 39829900
Yes, I am trying to get the number of tables that have an email or URL field where EMAIL or URL field is blank in table
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39829909
Did you take a look at what I posted in http:#a39825561 ?

You can add an additional column check for the URL column.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now