Nested outer join
394265Aug 13 2003 — edited Aug 17 2003I need to select records, one for each index having a list of column pairs indicating column name and id.
An index may have one or more columns (obviously).
I'll need one record from user_indexes, at least one record from user_ind_columns for which I will have one corresponding record from user_tab_columns.
Example output:
table_name, index_name, column_name, column_id, column_name, column_id ...
I wrote what looked like the correct syntax (unfortunately, Oracle's meta data is not normalized):
select i.table_name, i.index_name,
c1.column_name, c1.column_id,
c2.column_name, c2.column_id,
c3.column_name, c3.column_id
from used_indexes i,
user_ind_columns ic1, user_tab_columns c1,
user_ind_columns ic2, user_tab_columns c2,
user_ind_columns ic3, user_tab_columns c3
where i.uniqueness='UNIQUE'
and i.table_name = 'CUST'
and i.table_name = ic1.table_name
and i.index_name = ic1.index_name
and ic1.table_name = c1.table_name
and ic1.column_name = c1.column_name
and ic1.column_position = 1
and i.table_name = ic2.table_name(+)
and i.index_name = ic2.index_name(+)
and ic2.column_name = c2.column_name
and ic2.table_name = c2.table_name
and ic2.column_position = 2
and i.table_name = ic3.table_name(+)
and i.index_name = ic3.index_name(+)
and ic3.column_name = c3.column_name
and ic3.table_name = c3.table_name
and ic3.column_position = 3
This query seems to 'hang' in SQL*Plus not returning any results or errors... EVER! Any ideas as to what the problem might be? Any suggestions as to how to create this query in a more suportable way? I will have to extend this to include up to 10 index fields for each index.
Thanks,
Jim