The following script gives the list of child database objects (other than tables) and the corresponding parent database object(s). When object X refers to object Y, X is a child of Y. Additionally, a parent object may be referred by many child objects. And an object may refer many parents. This list is extremely helpful when creating all the database objects -- excluding tables -- in the future. The significance of the script's output is that we can proceed with building the objects of the database in the same order as it appears in the list, so that when a particular object is being created, all its parents have already been created.
REM Note : The result, apart from excluding table dependencies
REM ( Foreign Key References ), also excludes objects
REM that do not refer to any other object.
CLEAR COLUMNS
CLEAR BREAKS
SET PAGESIZE 50
SET FEEDBACK OFF
SET PAUSE ON
COLUMN "This Child Depends on" FORMAT A39
COLUMN "This Parent" FORMAT A39
BREAK ON "This Child Depends on" SKIP 2
SPOOL OBJ_DEPEND
SELECT A.OBJECT_NAME || ' ( ' || A.OBJECT_TYPE || ' )' "This Child Depends on",
B.OBJECT_NAME || ' ( ' || B.OBJECT_TYPE || ' )' "This Parent"
FROM SYS.DEPENDENCY$ C,
USER_OBJECTS A,
USER_OBJECTS B
WHERE C.P_OBJ# = B.OBJECT_ID
AND C.D_OBJ# = A.OBJECT_ID
AND A.STATUS = 'VALID'
AND B.STATUS = 'VALID'
ORDER BY D_TIMESTAMP, "This Child Depends on"
/
SPOOL OFF
CLEAR COLUMNS
CLEAR BREAKS
SET FEEDBACK ON
CLEAR COLUMNS
CLEAR BREAK
SET PAUSE ON
SET FEEDBACK OFF
SET PAGESIZE 20
COLUMN "This Table References" FORMAT A30
COLUMN "This Table" FORMAT A30
BREAK ON "This Table References" SKIP 2
SPOOL TAB_DEPEND
SELECT A.TABLE_NAME "This Table References",
DECODE( A.R_OWNER,
A.OWNER, B.TABLE_NAME,
A.R_OWNER || '.' || B.TABLE_NAME ) "This Table"
FROM USER_CONSTRAINTS A,
USER_CONSTRAINTS B
WHERE A.R_CONSTRAINT_NAME = B.CONSTRAINT_NAME
AND A.CONSTRAINT_TYPE = 'R'
AND B.CONSTRAINT_TYPE IN ( 'U', 'P' )
GROUP BY A.TABLE_NAME,
DECODE( A.R_OWNER, A.OWNER, B.TABLE_NAME,
A.R_OWNER || '.' || B.TABLE_NAME )
ORDER BY 1, 2
/
SPOOL OFF
CLEAR COLUMNS
CLEAR BREAKS