Top Banner
8 Copyright © 2004, Oracle. All rights reserved. Managing Dependencies
32
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Les08

8Copyright © 2004, Oracle. All rights reserved.

Managing Dependencies

Page 2: Les08

8-2 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

Page 3: Les08

8-3 Copyright © 2004, Oracle. All rights reserved.

Understanding Dependencies

Table

View

Database trigger

Procedure

Function

Package body

Package specification

User-defined objectand collection types

Function

Package specification

Procedure

Sequence

Synonym

Table

View

User-defined objectand collection types

Referenced objectsDependent objects

Page 4: Les08

8-4 Copyright © 2004, Oracle. All rights reserved.

Dependencies

View orprocedure

Directdependency

Referenced

Indirectdependency

Directdependency

Dependent

Table

Referenced

xxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvv

Procedure

Dependent

Page 5: Les08

8-5 Copyright © 2004, Oracle. All rights reserved.

Local Dependencies

xxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvvvvvvvvvvvvvvv

Procedure View

Local references

Procedure Table

vvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvv

Direct localdependency

Page 6: Les08

8-6 Copyright © 2004, Oracle. All rights reserved.

xxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvvvvvvvvvvvvvvv

Procedure View

Local references

Procedure Table

vvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvv

Direct localdependency

Local Dependencies

The Oracle server implicitly recompiles any INVALID object when the object is next called.

Definitionchange

INVALIDINVALIDINVALID

Page 7: Les08

8-7 Copyright © 2004, Oracle. All rights reserved.

xxxxxxxxxxxxxxxxxxxxxvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxvvvvvvvvvvvvvvvvvvvvv

xxxxxxxxxxxxxxxxxxxxxvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxvvvvvvvvvvvvvvvvvvvvv

ADD_EMPprocedure

QUERY_EMPprocedure

EMPLOYEES table

EMP_VW view

A Scenario of Local Dependencies

Page 8: Les08

8-8 Copyright © 2004, Oracle. All rights reserved.

Displaying Direct Dependencies by Using USER_DEPENDENCIES

SELECT name, type, referenced_name, referenced_typeFROM user_dependenciesWHERE referenced_name IN ('EMPLOYEES','EMP_VW' );

……

Page 9: Les08

8-9 Copyright © 2004, Oracle. All rights reserved.

Displaying Direct and Indirect Dependencies

1. Run the script utldtree.sql 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')

Page 10: Les08

8-10 Copyright © 2004, Oracle. All rights reserved.

Displaying Dependencies

DEPTREE view

SELECT nested_level, type, nameFROM deptreeORDER BY seq#;

Page 11: Les08

8-11 Copyright © 2004, Oracle. All rights reserved.

EMPLOYEES table

REDUCE_SALprocedure

RAISE_SALprocedure

Another Scenario of Local Dependencies

xxxxxxxxxxxxxxxxxxxxxvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxvvvvvvvvvvvvvvvvvvvvv

xxxxxxxxxxxxxxxxxxxxxvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxvvvvvvvvvvvvvvvvvvvvv

Page 12: Les08

8-12 Copyright © 2004, Oracle. All rights reserved.

QUERY_EMPprocedure EMPLOYEES public synonym

A Scenario of Local Naming Dependencies

EMPLOYEEStable

xxxxxxxxxxxxxxxxxxxxxvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxvvvvvvvvvvvvvvvvvvvvv

Page 13: Les08

8-13 Copyright © 2004, Oracle. All rights reserved.

Understanding Remote Dependencies

xxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvv

Procedure ViewProcedure Table

vvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvv

Direct localdependency

Direct remotedependency

Local and remote references

Network

Page 14: Les08

8-14 Copyright © 2004, Oracle. All rights reserved.

Understanding Remote Dependencies

xxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvv

Procedure ViewProcedure Table

vvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvv

Direct localdependency

Direct remotedependency

Local and remote references

Network

Definitionchange

INVALIDINVALIDVALID

Page 15: Les08

8-15 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

Page 16: Les08

8-16 Copyright © 2004, Oracle. All rights reserved.

REMOTE_DEPENDENCIES_MODE Parameter

Setting REMOTE_DEPENDENCIES_MODE:

• As an init.ora parameterREMOTE_DEPENDENCIES_MODE = value

• At the system levelALTER SYSTEM SET REMOTE_DEPENDENCIES_MODE = value

• At the session levelALTER SESSION SET REMOTE_DEPENDENCIES_MODE = value

Page 17: Les08

8-17 Copyright © 2004, Oracle. All rights reserved.

Remote Dependencies and Time Stamp Mode

xxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvv

Procedure ViewProcedure Table

vvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvv

Network

Network

Page 18: Les08

8-18 Copyright © 2004, Oracle. All rights reserved.

xxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvv

Procedure ViewProcedure Table

vvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvvxxxxxxxxxxxxxxvvvvvvvvvvvvvv

Network

Network

Remote Dependencies and Time Stamp Mode

Definitionchange

INVALIDINVALIDVALID

Page 19: Les08

8-19 Copyright © 2004, Oracle. All rights reserved.

Remote Procedure B Compiles at 8:00 a.m.

Remote procedure B

Valid

Compiles

Page 20: Les08

8-20 Copyright © 2004, Oracle. All rights reserved.

Local Procedure A Compiles at 9:00 a.m.

Local procedure A

Valid

Remote procedure B

Time stampof B

Valid

Time stamp of A

Record time stamp of B

Page 21: Les08

8-21 Copyright © 2004, Oracle. All rights reserved.

Execute Procedure A

Local procedure A

Valid

Remote procedure B

Time stampof B

Valid

Time stamp of A

Time stamp of B

Time stampcomparison

Execute B

Page 22: Les08

8-22 Copyright © 2004, Oracle. All rights reserved.

Remote Procedure B Recompiled at 11:00 a.m.

Valid

Compiles

Remote procedure B

Page 23: Les08

8-23 Copyright © 2004, Oracle. All rights reserved.

Local procedure A

Valid

Remote procedure B

Time stampof B

Valid

Time stamp of A

Time stamp of B

Time stampcomparison

ERROR

Invalid

Execute Procedure A

Page 24: Les08

8-24 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.

Page 25: Les08

8-25 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]];

Page 26: Les08

8-26 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

Page 27: Les08

8-27 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

Page 28: Les08

8-28 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

Page 29: Les08

8-29 Copyright © 2004, Oracle. All rights reserved.

Packages and Dependencies

Package body

Procedure Adefinition

Definition changed

Procedure Adeclaration

Package specification

ValidStand-aloneprocedure

Valid

Page 30: Les08

8-30 Copyright © 2004, Oracle. All rights reserved.

Package body

Procedure Adefinition

Procedure Adeclaration

Package specification

Valid

Packages and Dependencies

Stand-aloneprocedure

Definition changed

Invalid

Page 31: Les08

8-31 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

Page 32: Les08

8-32 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