Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: hierarchical tree

Re: hierarchical tree

From: Patrick Z <zweifpf_at_dhfs.state.wi.us>
Date: 14 Jun 2002 12:57:29 -0700
Message-ID: <c038de85.0206141157.d1e6bb6@posting.google.com>


Greeting Martin,

Try the following script. I use it quite a bit with minor tweaking based on what I am looking for. This is the 'vanilla' version.

REM PURPOSE:
REM The script below generates a hierarchical list of referring REM and referenced tables in any Oracle schema. REM
REM The SQL script generates a hierarchical list of tables with REM a level number (tables that are linked with foreign key REM constraints) from any Oracle schema. The list is useful in REM identifying the 'order of tables,' while loading data, REM dropping tables, or deleting rows from tables. REM
REM An example output spool file 'level_tree.lis' looks like this: REM
REM FORMAT: schema.table_name(level number) REM

REM    schema1.table_three(4)     : table_three is at level 4 
REM    -   schema1.table_two(3)   : table_three references table_two 
REM    -   schema1.table_one(2)   : table_two references table_one 
REM - schema2.table_five(1): table_one references table_five in schema2
REM - schema1.table_four(1) : table_three references table_four REM
REM
REM The script collects referential integrity constraints data from REM the data dictionary tables, creates and populates temporary REM tables and prints the hierarchical table list.
REM ------------------------------------------------------------------------
REM EXAMPLE:
REM SYSTEM.CODE_VALUES(1)
REM - SYSTEM.CODE_TYPES()
REM  ----------------------- 

REM SYSTEM.CUSTOMER(1)
REM - SYSTEM.DIVISION()
REM    ----------------------- 

REM SYSTEM.CUSTOMER_ADDRESS(1)
REM    -  SYSTEM.CUSTOMER() 
REM    -    SYSTEM.DIVISION() 
REM    ----------------------- 

REM SYSTEM.CUSTOMER_PHONE(1)
REM    -  SYSTEM.CUSTOMER_ADDRESS() 
REM    -    SYSTEM.CUSTOMER() 
REM    -      SYSTEM.DIVISION() 
REM    ----------------------- 

REM SYSTEM.DEF$_CALLDEST(1)
REM    -  SYSTEM.DEF$_CALL() 
REM    -  SYSTEM.DEF$_DESTINATION() 
REM    ----------------------- 

REM SYSTEM.DIVISION_REGION(1)
REM - SYSTEM.DIVISION()
REM    ----------------------- 

REM
REM ------------------------------------------------------------------------
REM DISCLAIMER:
REM This script is provided for educational purposes only. It is NOT
REM supported by Oracle Support Services. REM The script has been tested and appears to work as intended. REM You should always run new scripts on a test instance initially.
REM ------------------------------------------------------------------------
REM
REM Changes : Added foreign key names to script REM
REM
REM
REM Main text of script follows:    

--

      Table name   Level number  
      -----------  ------------  
      table_five     1  
      table_four     1  
      table_one      2  
      table_two      3  
      table_three    4   
   ----------------------------------------------------------------- 
*/
drop table level_tab
/

Good luck,
Patrick Received on Fri Jun 14 2002 - 14:57:29 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US