Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Parse SQL query and extract source tables and columns

506350Apr 6 2010 — edited Apr 7 2010
Hello,

I have a set of SQL queries and I have to extract the source tables and columns from them.

For example:
Let's imagine that we have two tables
CREATE TABLE T1 (col1 number, col2 number, col3 number)
CREATE TABLE T2 (col1 number, col2 number, col3 number)

We have the following query:
SELECT
T1.col1,
T1.col2 + T1.col3 as field2
FROM T1 INNER JOIN T2 ON T1.col2=T2.col2
WHERE T2.col1 = 1

So, as a result I would like to have:
Order Table Column
1 T1 col1
2 T1 col2
2 T1 col3

Optionally, I would like to have a list of all dependency columns (columns used in "ON", "WHERE" and "GROUP BY" clauses:
Table Column
T1 col2
T2 col1
T2 col2

I have tried different approaches but without any success. Any help is appreciated. Thank you in advance.

Best regards,
Beroetz
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 5 2010
Added on Apr 6 2010
2 comments
1,798 views