Avatar of ThomasCox
ThomasCox

asked on 

Compare SQL Query Result Set Column Names to the Column Names in an exising Table

I know how to compare the column names in two tables by querying the SYS.All_Tab_COLUMNS Table.  

However, I want to compare the columns in an existing table in the SYS.All_Tab_COLUMNS Table to the Column Names in the Result Set of a SQL Query.

l have been looking all over and cannot find a resolution.

Thanks
Oracle Database

Avatar of undefined
Last Comment
mradovan10
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Queries do not have columns per say.  They are 'aliases' and not stored anwhere.

If you can provide a little more infomration about the actual problem you are trying to solve we might be able to come up with a solution.

This was also posted in SQL Server.  Is this Oracle or SQL Server related?
Avatar of ThomasCox
ThomasCox

ASKER

I was given a very long procedure to create a table form a Select query against another table.

I need a quick way to compare the column aliases and position in the Select Query to the column names and position in the Table.

There are a few hundred columns involved on both sides.

I do not know how the guy who created the query designed it but it is obvious to the eye that some column names are different in some places and they are out of order in others.  He did not use a Select * for obvious reasons.
Avatar of ThomasCox
ThomasCox

ASKER

Forgot your other question.  It is an Oracle Database using SQL.
Try this:

select column_name,column_id from useR_tab_columns where table_name='TAB1'
minus
select column_name,column_id from useR_tab_columns where table_name='TAB2'
/
Avatar of ThomasCox
ThomasCox

ASKER

I need it to compare a SQL Query Results Column aliases against the Column Names of an exising table.

Your comment compares a Table to a Table which I already know how to accomplish.

I need Query to Table.

Thanks!
SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
If you want to walk through this code and tweak it, it looks like you can create a procedure that will extract the curosr columns:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1035431863958
ASKER CERTIFIED SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
Avatar of mradovan10
mradovan10

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Oracle Database
Oracle Database

Oracle is an object-relational database management system. It supports a large number of languages and application development frameworks. Its primary languages are SQL, PL/SQL and Java, but it also includes support for C and C++. Oracle also has its own enterprise modules and application server software.

81K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo