Solved

SQL to check if the column is blank in multiple tables

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What is the version of ojdbc6.jar 2 39
Oracle sql query 7 43
How to free up undo space? 3 27
SQL Developer 6 27
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to take different types of Oracle backups using RMAN.

911 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

26 Experts available now in Live!

Get 1:1 Help Now