Managing Dependencies

Copyright © 2006, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to do the following: • Track procedural dependencies • Predict the effect of changing a database object on stored procedures and functions • Manage procedural dependencies

8-2

Copyright © 2006, Oracle. All rights reserved.

Understanding Dependencies
Dependent objects Database trigger Package specification Function Procedure Procedure Referenced objects Function

Sequence
Package body Synonym Package specification Table User-defined object and collection types View View User-defined object and collection types

8-3

Copyright © 2006, Oracle. All rights reserved.

Dependencies Procedure xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv View or procedure Direct dependency Referenced Dependent Table Direct dependency Dependent Indirect dependency Referenced 8-4 Copyright © 2006. All rights reserved. Oracle. .

Oracle. All rights reserved. .Local Dependencies Procedure xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv vvvvvvvvvvvvvv Procedure vvvvvvvvvvvvv v xxxxxxxxxxxxx x vvvvvvvvvvvvv v xxxxxxxxxxxxx x vvvvvvvvvvvvv v xxxxxxxxxxxxx x vvvvvvvvvvvvv v View Table Local references Direct local dependency 8-5 Copyright © 2006.

8-6 Copyright © 2006. All rights reserved. . Oracle.Local Dependencies Procedure xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv vvvvvvvvvvvvvv Procedure vvvvvvvvvvvvv v xxxxxxxxxxxxx x vvvvvvvvvvvvv v xxxxxxxxxxxxx x vvvvvvvvvvvvv v xxxxxxxxxxxxx x vvvvvvvvvvvvv v View Table INVALID Local references INVALID INVALID Direct local dependency Definition change The Oracle server implicitly recompiles any INVALID object when the object is next called.

8-7 . All rights reserved. Oracle.A Scenario of Local Dependencies ADD_EMP procedure xxxxxxxxxxxxxxxxxxxxx vvvvvvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvvvvvv vvvvvvxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxx vvvvvvvvvvvvvvvvvvvvv EMP_VW view … EMPLOYEES table QUERY_EMP procedure xxxxxxxxxxxxxxxxxxxxx vvvvvvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvvvvvv vvvvvvxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxx vvvvvvvvvvvvvvvvvvvvv … Copyright © 2006.

Oracle.Displaying Direct Dependencies by Using USER_DEPENDENCIES SELECT name. referenced_type FROM user_dependencies WHERE referenced_name IN ('EMPLOYEES'. . All rights reserved. referenced_name. … … 8-8 Copyright © 2006.'EMP_VW' ). type.

Oracle. All rights reserved.Displaying Direct and Indirect Dependencies 1. 2. EXECUTE deptree_fill('TABLE'.sql script that creates the objects that enable you to display the direct and indirect dependencies.'EMPLOYEES') 8-9 Copyright © 2006. Run the utldtree. .'SCOTT'. Execute the DEPTREE_FILL procedure.

… … 8-10 Copyright © 2006.Displaying Dependencies The DEPTREE view: SELECT nested_level. type. name FROM deptree ORDER BY seq#. Oracle. . All rights reserved.

Oracle. All rights reserved.Another Scenario of Local Dependencies xxxxxxxxxxxxxxxxxxxxx vvvvvvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvvvvvv vvvvvvxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxx vvvvvvvvvvvvvvvvvvvvv REDUCE_SAL procedure RAISE_SAL procedure EMPLOYEES table xxxxxxxxxxxxxxxxxxxxx vvvvvvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvvvvvv vvvvvvxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxx vvvvvvvvvvvvvvvvvvvvv … 8-11 Copyright © 2006. .

Oracle.A Scenario of Local Naming Dependencies QUERY_EMP procedure xxxxxxxxxxxxxxxxxxxxx vvvvvvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvvvvvv vvvvvvxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxx vvvvvvvvvvvvvvvvvvvvv EMPLOYEES public synonym … EMPLOYEES table … 8-12 Copyright © 2006. All rights reserved. .

Oracle. All rights reserved. .Understanding Remote Dependencies Procedure xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv Procedure vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv View Table Network Local and remote references Direct local dependency 8-13 Direct remote dependency Copyright © 2006.

.Understanding Remote Dependencies Procedure xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv Procedure vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv View Table Network VALID INVALID INVALID Local and remote references Direct local dependency 8-14 Direct remote dependency Definition change Copyright © 2006. All rights reserved. Oracle.

Concepts of Remote Dependencies Remote dependencies are governed by the mode that is chosen by the user: • TIMESTAMP checking • SIGNATURE checking 8-15 Copyright © 2006. All rights reserved. Oracle. .

ora parameter REMOTE_DEPENDENCIES_MODE = value At the system level ALTER SYSTEM SET REMOTE_DEPENDENCIES_MODE = value At the session level ALTER SESSION SET REMOTE_DEPENDENCIES_MODE = value • 8-16 Copyright © 2006.REMOTE_DEPENDENCIES_MODE Parameter Setting REMOTE_DEPENDENCIES_MODE: • • As an init. . Oracle. All rights reserved.

Oracle.Remote Dependencies and Time Stamp Mode Procedure xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv Procedure View Table Network vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv Network 8-17 Copyright © 2006. . All rights reserved.

8-18 .Remote Dependencies and Time Stamp Mode Procedure xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv Procedure View Table Network vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv xxxxxxxxxxxxxx vvvvvvvvvvvvvv VALID INVALID INVALID Network Definition change Copyright © 2006. Oracle. All rights reserved.

Remote Procedure B Compiles at 8:00 a. Oracle. Remote procedure B Compiles Valid 8-19 Copyright © 2006. . All rights reserved.m.

. Local procedure A Remote procedure B Time stamp of A Valid Record time stamp of B Time stamp of B Valid 8-20 Copyright © 2006.Local Procedure A Compiles at 9:00 a. Oracle.m. All rights reserved.

Execute Procedure A Local procedure A Remote procedure B Time stamp comparison Time stamp of A Valid Time stamp of B Time stamp of B Valid Execute B 8-21 Copyright © 2006. Oracle. All rights reserved. .

m. Oracle. All rights reserved.Remote Procedure B Recompiled at 11:00 a. Remote procedure B Compiles Valid 8-22 Copyright © 2006. .

Oracle. . All rights reserved.Execute Procedure A Local procedure A Remote procedure B Time stamp comparison Time stamp of A Valid Time stamp of B Invalid Time stamp of B Valid ERROR 8-23 Copyright © 2006.

8-24 Copyright © 2006. .Signature Mode • The signature of a procedure is: – The name of the procedure – The data types of the parameters – The modes of the parameters • • The signature of the remote procedure is saved in the local procedure. the signature of the referenced remote procedure is compared. All rights reserved. When executing a dependent procedure. Oracle.

8-25 Copyright © 2006. . Oracle.]procedure_name COMPILE.Recompiling a PL/SQL Program Unit Recompilation: • Is handled automatically through implicit run-time recompilation • Is handled through explicit recompilation with the ALTER statement ALTER PROCEDURE [SCHEMA.]package_name COMPILE [PACKAGE | SPECIFICATION | BODY].]function_name COMPILE. All rights reserved. ALTER TRIGGER trigger_name [COMPILE[DEBUG]]. ALTER PACKAGE [SCHEMA. ALTER FUNCTION [SCHEMA.

. Oracle. All rights reserved.Unsuccessful Recompilation Recompiling dependent procedures and functions is unsuccessful when: • The referenced object is dropped or renamed • The data type of the referenced column is changed • The referenced column is dropped • A referenced view is replaced by a view with different columns • The parameter list of a referenced procedure is modified 8-26 Copyright © 2006.

All rights reserved. Oracle. . but a public table that has the same name and structure exists • The PL/SQL body of a referenced procedure has been modified and recompiled successfully 8-27 Copyright © 2006.Successful Recompilation Recompiling dependent procedures and functions is successful if: • The referenced table has new columns • The data type of referenced columns has not changed • A private table is dropped.

Oracle. .Recompilation of Procedures Minimize dependency failures by: • Declaring records with the %ROWTYPE attribute • Declaring variables with the %TYPE attribute • Querying with the SELECT * notation • Including a column list with INSERT statements 8-28 Copyright © 2006. All rights reserved.

. Oracle. All rights reserved.Packages and Dependencies Package specification Stand-alone procedure Valid Package body Procedure A declaration Valid Procedure A definition Definition changed 8-29 Copyright © 2006.

Oracle. All rights reserved.Packages and Dependencies Package specification Procedure A declaration Valid Package body Stand-alone procedure Definition changed Procedure A definition Invalid 8-30 Copyright © 2006. .

All rights reserved. Oracle. .Summary In this lesson. you should have learned how to: • Keep track of dependent procedures • Recompile procedures manually as soon as possible after the definition of a database object changes 8-31 Copyright © 2006.

and packages 8-32 Copyright © 2006. All rights reserved. Oracle.Practice 8: Overview This practice covers the following topics: • Using DEPTREE_FILL and IDEPTREE to view dependencies • Recompiling procedures. functions. .