How to compare 2 VIEWS in Oracle

I would like to know the differences in columns between 2 Views.
To give a simplify example View A_Old can have 3 while View A can have 5 columns.
There are 3 columns common to both views. How can I create a query to return the columns which arent present in both
LVL 1
diteps06Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sdstuberCommented:
if you know VIEW_A has more columns than VIEW_A_OLD try this...
select column_name,data_type from dba_tab_columns where owner = 'NEW_OWNER' and table_name = 'VIEW_A'
minus
select  column_name,data_type from dba_tab_columns where owner = 'OLD_OWNER' and ttable_name = 'VIEW_A_OLD'

Open in new window

0
sdstuberCommented:
if you have no idea what the difference between views A and B might be,  then try this...
  SELECT   owner, table_name view_name, column_name, data_type
    FROM   dba_tab_columns dtc
   WHERE   owner IN ('VIEW_A_OWNER', 'VIEW_B_OWNER')
       AND table_name IN ('VIEW_A', 'VIEW_B')
       AND EXISTS (SELECT   *
                     FROM   (SELECT   *
                               FROM   (SELECT   column_name, data_type
                                         FROM   dba_tab_columns
                                        WHERE   owner = 'VIEW_A_OWNER' AND table_name = 'VIEW_A'
                                       UNION
                                       SELECT   column_name, data_type
                                         FROM   dba_tab_columns
                                        WHERE   owner = 'VIEW_B_OWNER' AND table_name = 'VIEW_B')
                             MINUS
                             SELECT   *
                               FROM   (SELECT   column_name, data_type
                                         FROM   dba_tab_columns
                                        WHERE   owner = 'VIEW_A_OWNER' AND table_name = 'VIEW_A'
                                       INTERSECT
                                       SELECT   column_name, data_type
                                         FROM   dba_tab_columns
                                        WHERE   owner = 'VIEW_B_OWNER' AND table_name = 'VIEW_B')) x
                    WHERE   x.column_name = dtc.column_name AND x.data_type = dtc.data_type)
ORDER BY   owner, view_name, column_name

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
I like this one much more, as you have to edit things on one place only:

select    a.column_name,a.data_type, b.column_name, b.data_type
from dba_tab_columns a full join dba_tab_columns b
  on a.column_name = b.column_name and a.data_type = b.data_type
 and a.owner = 'OWNER_NEW' and a.table_name = 'VIEW_NEW'
 and b.owner = 'OWNER_OLD' and b.table_name = 'VIEW_OLD'
where a.column_name is null or b.column_name is null
   or a.data_type != b.data_type

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

diteps06Author Commented:
The question is about View which a join of one or more tables.
It doesn't regard Tables.
I expected functions like DBA_VIEWS OR VIEW_NAME
0
sdstuberCommented:
did you try the queries?

dba_tab_columns has columns for both tables and views
0
diteps06Author Commented:
I had the error 'table or view doesn't exist' refering to dba_tab_columns.
Can it be a priviliege problem
0
sdstuberCommented:
Maybe, try all_tab_columns instead
0
diteps06Author Commented:
Thanks alot.
I used the query when you have no idea about the differences between the Views.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.