Solved

SQL to check if the column is blank in multiple tables

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

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…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
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

840 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