Oracle: Traversing a graph of my foreign keys? Given a table, what is a query that will show foreign key constrains, both immediate and nested? I.e. if T2 has an FK on T1, and T3 has an FK on T2, I would like to show T1 -> T2 -> T3.
I usually use this statement.

with fk_list as (
  select parent_table.table_name parent, 
         parent_cons.constraint_name as pk_constraint,
         child_table.table_name child,
         child_cons.constraint_name as fk_constraint
  from user_tables parent_table
    join user_constraints parent_cons on parent_table.table_name = parent_cons.table_name and parent_cons.constraint_type IN ('P', 'U')
    join user_constraints child_cons on child_cons.r_constraint_name = parent_cons.constraint_name and child_cons.constraint_type   = 'R'
    join user_tables child_table on child_table.table_name = child_cons.table_name and child_table.table_name &lt;&gt; parent_table.table_name
)
select level, 
       fl.child,
       (select listagg(fk.column_name,',') within group (order by fk.position) from user_cons_columns fk where fk.constraint_name = fl.fk_constraint) as fk_columns,
       fl.parent,
       (select listagg(pk.column_name,',') within group (order by pk.position) from user_cons_columns pk where pk.constraint_name = fl.pk_constraint) as pk_columns
from fk_list fl
where fl.child &lt;&gt; fl.parent
start with fl.parent = 'root table'
connect by prior fl.child = fl.parent
order by level;


It is not the most efficient one, but it does work for me.

Note that it requires 11.2 due to the use of listagg()