8
Managing Dependencies
Copyright © 2004, 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 © 2004, Oracle. All rights reserved.
Understanding Dependencies
Dependent objects Referenced objects
Table Function
View Package specification
Database trigger Procedure
Procedure Sequence
Function Synonym
Package body Table
Package specification View
User-defined object User-defined object
and collection types and collection types
8-3 Copyright © 2004, Oracle. All rights reserved.
Dependencies
View or
Procedure procedure Table
xxxxxxxxxxxxxx
vvvvvvvvvvvvvv
xxxxxxxxxxxxxx Direct Direct
vvvvvvvvvvvvvv
xxxxxxxxxxxxxx
dependency dependency
vvvvvvvvvvvvvv
xxxxxxxxxxxxxx
vvvvvvvvvvvvvv
xxxxxxxxxxxxxx
vvvvvvvvvvvvvv
Referenced
Dependent
Dependent Indirect Referenced
dependency
8-4 Copyright © 2004, Oracle. All rights reserved.
Local Dependencies
Procedure Procedure View Table
xxxxxxxxxxxxxx vvvvvvvvvvvvv
vvvvvvvvvvvvvv v
xxxxxxxxxxxxxx xxxxxxxxxxxxx
vvvvvvvvvvvvvv x
xxxxxxxxxxxxxx vvvvvvvvvvvvv
vvvvvvvvvvvvvv v
vvvvvvvvvvvvvv xxxxxxxxxxxxx
x
vvvvvvvvvvvvv
v
xxxxxxxxxxxxx
Local references x
vvvvvvvvvvvvv
v
Direct local
dependency
8-5 Copyright © 2004, Oracle. All rights reserved.
Local Dependencies
Procedure Procedure View Table
xxxxxxxxxxxxxx vvvvvvvvvvvvv
vvvvvvvvvvvvvv v
xxxxxxxxxxxxxx xxxxxxxxxxxxx
vvvvvvvvvvvvvv x
xxxxxxxxxxxxxx vvvvvvvvvvvvv
vvvvvvvvvvvvvv v
vvvvvvvvvvvvvv xxxxxxxxxxxxx
x
INVALID INVALID
vvvvvvvvvvvvv
v
INVALID
xxxxxxxxxxxxx
Local references x
vvvvvvvvvvvvv
v
Direct local Definition
dependency change
The Oracle server implicitly recompiles any INVALID
object when the object is next called.
8-6 Copyright © 2004, Oracle. All rights reserved.
A Scenario of Local Dependencies
ADD_EMP EMP_VW view
procedure
xxxxxxxxxxxxxxxxxxxxx
vvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvv
vvvvvvxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxx
vvvvvvvvvvvvvvvvvvvvv
QUERY_EMP EMPLOYEES table
procedure
xxxxxxxxxxxxxxxxxxxxx
vvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvv
vvvvvvxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxx
…
vvvvvvvvvvvvvvvvvvvvv
8-7 Copyright © 2004, Oracle. All rights reserved.
Displaying Direct Dependencies by Using
USER_DEPENDENCIES
SELECT name, type, referenced_name, referenced_type
FROM user_dependencies
WHERE referenced_name IN ('EMPLOYEES','EMP_VW' );
…
…
8-8 Copyright © 2004, Oracle. All rights reserved.
Displaying Direct and Indirect
Dependencies
1. Run the script [Link] that creates the
objects that enable you to display the direct and
indirect dependencies.
2. Execute the DEPTREE_FILL procedure.
EXECUTE deptree_fill('TABLE','SCOTT','EMPLOYEES')
8-9 Copyright © 2004, Oracle. All rights reserved.
Displaying Dependencies
DEPTREE view
SELECT nested_level, type, name
FROM deptree
ORDER BY seq#;
8-10 Copyright © 2004, Oracle. All rights reserved.
Another Scenario of Local Dependencies
xxxxxxxxxxxxxxxxxxxxx
vvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvv
REDUCE_SAL vvvvvvvvvvvvvvvvvvvvv
procedure vvvvvvxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxx
vvvvvvvvvvvvvvvvvvvvv
RAISE_SAL
procedure xxxxxxxxxxxxxxxxxxxxx
vvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvv
EMPLOYEES table vvvvvvxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxx
vvvvvvvvvvvvvvvvvvvvv
8-11 Copyright © 2004, Oracle. All rights reserved.
A Scenario of Local Naming Dependencies
QUERY_EMP
procedure EMPLOYEES public synonym
xxxxxxxxxxxxxxxxxxxxx
vvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvv
vvvvvvxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxx
vvvvvvvvvvvvvvvvvvvvv
…
EMPLOYEES
table
8-12 Copyright © 2004, Oracle. All rights reserved.
Understanding Remote Dependencies
Procedure Procedure View Table
xxxxxxxxxxxxxx
vvvvvvvvvvvvvv vvvvvvvvvvvvvv
xxxxxxxxxxxxxx xxxxxxxxxxxxxx
vvvvvvvvvvvvvv vvvvvvvvvvvvvv
xxxxxxxxxxxxxx xxxxxxxxxxxxxx
vvvvvvvvvvvvvv Network vvvvvvvvvvvvvv
xxxxxxxxxxxxxx xxxxxxxxxxxxxx
vvvvvvvvvvvvvv vvvvvvvvvvvvvv
xxxxxxxxxxxxxx
vvvvvvvvvvvvvv
Local and remote references
Direct local Direct remote
dependency dependency
8-13 Copyright © 2004, Oracle. All rights reserved.
Understanding Remote Dependencies
Procedure Procedure View Table
xxxxxxxxxxxxxx
vvvvvvvvvvvvvv vvvvvvvvvvvvvv
xxxxxxxxxxxxxx xxxxxxxxxxxxxx
vvvvvvvvvvvvvv vvvvvvvvvvvvvv
xxxxxxxxxxxxxx xxxxxxxxxxxxxx
vvvvvvvvvvvvvv Network vvvvvvvvvvvvvv
xxxxxxxxxxxxxx xxxxxxxxxxxxxx
vvvvvvvvvvvvvv vvvvvvvvvvvvvv
xxxxxxxxxxxxxx
vvvvvvvvvvvvvv
VALID INVALID INVALID
Local and remote references
Direct local Direct remote Definition
dependency dependency change
8-14 Copyright © 2004, Oracle. All rights reserved.
Concepts of Remote Dependencies
Remote dependencies are governed by the mode that
is chosen by the user:
• TIMESTAMP checking
• SIGNATURE checking
8-15 Copyright © 2004, Oracle. All rights reserved.
REMOTE_DEPENDENCIES_MODE Parameter
Setting REMOTE_DEPENDENCIES_MODE:
• As an [Link] 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 © 2004, Oracle. All rights reserved.
Remote Dependencies and
Time Stamp Mode
Procedure Procedure View Table
xxxxxxxxxxxxxx
vvvvvvvvvvvvvv
xxxxxxxxxxxxxx
vvvvvvvvvvvvvv vvvvvvvvvvvvvv
xxxxxxxxxxxxxx xxxxxxxxxxxxxx
vvvvvvvvvvvvvv vvvvvvvvvvvvvv
xxxxxxxxxxxxxx Network xxxxxxxxxxxxxx
vvvvvvvvvvvvvv vvvvvvvvvvvvvv
xxxxxxxxxxxxxx xxxxxxxxxxxxxx
vvvvvvvvvvvvvv vvvvvvvvvvvvvv
Network
8-17 Copyright © 2004, Oracle. All rights reserved.
Remote Dependencies and
Time Stamp Mode
Procedure Procedure View Table
xxxxxxxxxxxxxx
vvvvvvvvvvvvvv
xxxxxxxxxxxxxx
vvvvvvvvvvvvvv vvvvvvvvvvvvvv
xxxxxxxxxxxxxx xxxxxxxxxxxxxx
vvvvvvvvvvvvvv vvvvvvvvvvvvvv
xxxxxxxxxxxxxx Network xxxxxxxxxxxxxx
vvvvvvvvvvvvvv vvvvvvvvvvvvvv
xxxxxxxxxxxxxx xxxxxxxxxxxxxx
vvvvvvvvvvvvvv vvvvvvvvvvvvvv
VALID INVALID INVALID
Definition
Network
change
8-18 Copyright © 2004, Oracle. All rights reserved.
Remote Procedure B Compiles
at 8:00 a.m.
Remote procedure B
Compiles
Valid
8-19 Copyright © 2004, Oracle. All rights reserved.
Local Procedure A Compiles
at 9:00 a.m.
Local procedure A Remote procedure B
Time stamp Record time Time stamp
of A stamp of B of B
Valid Valid
8-20 Copyright © 2004, Oracle. All rights reserved.
Execute Procedure A
Local procedure A Remote procedure B
Time stamp
comparison
Time stamp Time stamp Time stamp
of A of B of B
Execute B
Valid Valid
8-21 Copyright © 2004, Oracle. All rights reserved.
Remote Procedure B Recompiled
at 11:00 a.m.
Remote procedure B
Compiles
Valid
8-22 Copyright © 2004, Oracle. All rights reserved.
Execute Procedure A
Local procedure A Remote procedure B
Time stamp
comparison
Time stamp Time stamp Time stamp
of A of B of B
ERROR
Valid Invalid Valid
8-23 Copyright © 2004, Oracle. All rights reserved.
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.
• When executing a dependent procedure, the
signature of the referenced remote procedure is
compared.
8-24 Copyright © 2004, Oracle. All rights reserved.
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.]procedure_name COMPILE;
ALTER FUNCTION [SCHEMA.]function_name COMPILE;
ALTER PACKAGE [SCHEMA.]package_name
COMPILE [PACKAGE | SPECIFICATION | BODY];
ALTER TRIGGER trigger_name [COMPILE[DEBUG]];
8-25 Copyright © 2004, 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 © 2004, Oracle. All rights reserved.
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, 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 © 2004, Oracle. All rights reserved.
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 © 2004, Oracle. All rights reserved.
Packages and Dependencies
Package specification
Stand-alone Valid
Procedure A
procedure
declaration
Valid
Package body
Procedure A
definition
Definition changed
8-29 Copyright © 2004, Oracle. All rights reserved.
Packages and Dependencies
Package specification
Procedure A Valid
declaration
Package body
Stand-alone Procedure A
Invalid
procedure definition
Definition
changed
8-30 Copyright © 2004, Oracle. All rights reserved.
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 © 2004, Oracle. All rights reserved.
Practice 8: Overview
This practice covers the following topics:
• Using DEPTREE_FILL and IDEPTREE to view
dependencies
• Recompiling procedures, functions, and packages
8-32 Copyright © 2004, Oracle. All rights reserved.