?
Solved

SQL to check if the column is blank in multiple tables

Posted on 2014-01-31
6
Medium Priority
?
208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 2000 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 77

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
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 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.
Suggested Courses

752 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