Solved

SQL to check if the column is blank in multiple tables

Posted on 2014-01-31
6
203 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 32

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.

Question has a verified solution.

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

Suggested Solutions

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

809 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