Sunteți pe pagina 1din 3

ORACLE Way to find out the Dependency (Used By) of an Object

Suppose we have an instance named SCOTT with password TIGER at dwdev1. To track the Dependency (Used By) of an Object, we have to build some tables and functions on the basis of which, this utility will work.

1.1 Objective :
Database object dependency tracker utility is used to track the dependency of an object on other database objects. There are 2 utilities designed for this. One is for tracking the objects dependent on a given database object and another one is for tracking objects on which the given object is dependent. The definitions of some objects, including views and procedures, reference other objects, such as tables. As a result, the objects being defined are dependent on the objects referenced in their definitions. For example, a view is defined by a query that references tables or other views. A procedure's body can include SQL statements that reference other objects of a database. An object that references another object as part of its definition is called a dependent object, while the object being referenced is a referenced object. If you alter the definition of a referenced object, dependent objects may or may not continue to function without error, depending on the type of alteration. For example, if you drop a table, no view based on the dropped table is usable. Oracle automatically records dependencies among objects to alleviate the complex job of dependency management for the database administrator and users. For example, if you alter a table on which several stored procedures depend, Oracle automatically recompiles the dependent procedures the next time the procedures are referenced (run or compiled against). To manage dependencies among schema objects, all of the schema objects in a database have a status. Only dependent objects can be invalid. Tables, sequences, and synonyms are always valid.

The Utility describes all dependencies in the database between procedures, packages, functions, package bodies, and triggers, including dependencies on views created without any database links

1.2 Execute the attached code to extract the list of objects, which the dependent on given object.

-------------------------------------------------------CONNECT SCOTT/TIGER@dwdev1; -------------------------------------------------------CREATE GLOBAL TEMPORARY TABLE SHOW_DEPENDENCY_TREE_REV ( SerialNo number, obj_name varchar2(30), Obj_type varchar2(30), Obj_level Number(5), owner varchar2(30), dep_obj_type varchar2(30), dep_obj_name varchar2(400) ) ON COMMIT PRESERVE ROWS;

GRANT ALL ON SHOW_DEPENDENCY_TREE_REV TO PUBLIC; CREATE SYNONYM SHOW_DEPENDENCY_TREE_REV FOR SCOTT.SHOW_DEPENDENCY_TREE_REV; Create or replace PACKAGE DEPS_USES_REV AS /* Develop by Pankaj Kumar(C) [cc_pkum11] on 03.11.2009 for check the dependency of an object */ PROCEDURE Show_deps_REV(Obj_owner in varchar2, Obj_name in Varchar2, Obj_type in Varchar2, lvl in number default 0); END DEPS_USES_REV; /

CREATE OR REPLACE PACKAGE BODY DEPS_USES_REV AS /* Develop by Pankaj Kumar(C) [cc_pkum11] on 03.11.2009 for check the dependency of an object */ -------------------------------------------------------PROCEDURE Show_deps_REV(Obj_owner in varchar2, Obj_name in Varchar2, Obj_type in Varchar2, lvl in number default 0) IS Begin EXECUTE IMMEDIATE ('DELETE FROM SCOTT.SHOW_DEPENDENCY_TREE_REV'); COMMIT; insert into SCOTT.SHOW_DEPENDENCY_TREE_REV(SerialNo, obj_name, Obj_type, Obj_level, dep_obj_name, dep_obj_type, owner) select rownum, referenced_name, referenced_type, level, LPAD(' ', (LEVEL-1)*7)||name, type, owner from DBA_DEPENDENCIES connect by prior owner = referenced_owner and prior name = referenced_name and prior type = referenced_type start with referenced_owner = upper(Obj_owner) and referenced_name = upper(Obj_name) and referenced_type = upper(Obj_type); commit; end; end; /

Note: The code should be input with object owner, object name, Object type. Last input parameter value is zero 0 which is of no use now and soon be eliminated. The code is session specific due to some technical constraint. This empowers the code to be used by concurrent multiple user with a cons that it is session specific, means, if you run the code for a given object in a session, result can be seen only through that session. The result is powered with level through with which the object is referenced In hierarchical model

Below is the way by which code can be executed for a given table

BEGIN

DEPS_USES_REV.Show_deps_REV(OBJECT_OWNER, OBJECT_NAME, OBJECT_TYPE, 0); END; / SELECT * FROM SHOW_DEPENDENCY_TREE_REV; After successful execution of the code, below select statement needs to be executed to see the result on the same instance: SELECT * FROM SHOW_DEPENDENCY_TREE_REV;

Pankaj Kumar Garg AWC Softwares Noida 999901245

S-ar putea să vă placă și