oracle - program with pl/sql - lession 18

33
18 Copyright © Oracle Corporation, 2001. All rights reserved. Managing Dependencies

Upload: thuan-nguyen

Post on 11-Apr-2017

3.087 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Oracle - Program with PL/SQL - Lession 18

18Copyright © Oracle Corporation, 2001. All rights reserved.

Managing Dependencies

Page 2: Oracle - Program with PL/SQL - Lession 18

18-2 Copyright © Oracle Corporation, 2001. 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

upon stored procedures and functions• Manage procedural dependencies

Page 3: Oracle - Program with PL/SQL - Lession 18

18-3 Copyright © Oracle Corporation, 2001. All rights reserved.

Understanding Dependencies

Page 4: Oracle - Program with PL/SQL - Lession 18

18-4 Copyright © Oracle Corporation, 2001. All rights reserved.

Dependencies

Page 5: Oracle - Program with PL/SQL - Lession 18

18-5 Copyright © Oracle Corporation, 2001. All rights reserved.

Local Dependencies

Page 6: Oracle - Program with PL/SQL - Lession 18

18-6 Copyright © Oracle Corporation, 2001. All rights reserved.

Local Dependencies

Page 7: Oracle - Program with PL/SQL - Lession 18

18-7 Copyright © Oracle Corporation, 2001. All rights reserved.

A Scenario of Local Dependencies

Page 8: Oracle - Program with PL/SQL - Lession 18

18-8 Copyright © Oracle Corporation, 2001. All rights reserved.

create table aa as select * from locations;create view bb as select * from aa;select object_name, status from USER_OBJECTSwhere object_type IN ('TABLE','VIEW');alter table aa add (cc varchar2(10));select object_name, status from USER_OBJECTSwhere object_type IN ('TABLE','VIEW');desc bbselect * from bb;select object_name, status from USER_OBJECTSwhere object_type IN ('TABLE','VIEW');

Page 9: Oracle - Program with PL/SQL - Lession 18

18-9 Copyright © Oracle Corporation, 2001. All rights reserved.

Displaying Direct Dependencies by UsingUSER_DEPENDENCIES

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

Page 10: Oracle - Program with PL/SQL - Lession 18

18-10 Copyright © Oracle Corporation, 2001. All rights reserved.

Displaying Direct and IndirectDependencies

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(’FUNCTION’, ’ your USERNAME’,’VALID_DEPTID’)

Page 11: Oracle - Program with PL/SQL - Lession 18

18-11 Copyright © Oracle Corporation, 2001. All rights reserved.

Multiple-Column Subqueries

SELECT nested_level, type, nameFROM deptreeORDER BY seq#;

DEPTREE View

Page 12: Oracle - Program with PL/SQL - Lession 18

18-12 Copyright © Oracle Corporation, 2001. All rights reserved.

Another Scenario of Local Dependencies

Page 13: Oracle - Program with PL/SQL - Lession 18

18-13 Copyright © Oracle Corporation, 2001. All rights reserved.

A Scenario of Local NamingDependencies

Page 14: Oracle - Program with PL/SQL - Lession 18

18-14 Copyright © Oracle Corporation, 2001. All rights reserved.

Understanding Remote Dependencies

Page 15: Oracle - Program with PL/SQL - Lession 18

18-15 Copyright © Oracle Corporation, 2001. All rights reserved.

Understanding Remote Dependencies

Page 16: Oracle - Program with PL/SQL - Lession 18

18-16 Copyright © Oracle Corporation, 2001. All rights reserved.

Concepts of Remote Dependencies

• Remote dependencies are governed by the modechosen by the user:

• TIMESTAMP checking• SIGNATURE checking

Page 17: Oracle - Program with PL/SQL - Lession 18

18-17 Copyright © Oracle Corporation, 2001. All rights reserved.

Pairwise Comparison Subquery

Setting REMOTE_DEPENDENCIES_MODE:• As an init.ora parameter

REMOTE_DEPENDENCIES_MODE = value• At the system level

ALTER SYSTEM SETREMOTE_DEPENDENCIES_MODE = value

• At the session level ALTER SESSION SET

REMOTE_DEPENDENCIES_MODE = value

Page 18: Oracle - Program with PL/SQL - Lession 18

18-18 Copyright © Oracle Corporation, 2001. All rights reserved.

Remote Dependencies andTime Stamp Mode

Page 19: Oracle - Program with PL/SQL - Lession 18

18-19 Copyright © Oracle Corporation, 2001. All rights reserved.

Remote Dependencies andTime Stamp Mode

Page 20: Oracle - Program with PL/SQL - Lession 18

18-20 Copyright © Oracle Corporation, 2001. All rights reserved.

Remote Procedure B Compilesat 8:00 a.m.

Page 21: Oracle - Program with PL/SQL - Lession 18

18-21 Copyright © Oracle Corporation, 2001. All rights reserved.

Local Procedure A Compilesat 9:00 a.m.

Page 22: Oracle - Program with PL/SQL - Lession 18

18-22 Copyright © Oracle Corporation, 2001. All rights reserved.

Execute Procedure A

Page 23: Oracle - Program with PL/SQL - Lession 18

18-23 Copyright © Oracle Corporation, 2001. All rights reserved.

Remote Procedure B Recompiledat 11:00 a.m.

Page 24: Oracle - Program with PL/SQL - Lession 18

18-24 Copyright © Oracle Corporation, 2001. All rights reserved.

Execute Procedure A

Page 25: Oracle - Program with PL/SQL - Lession 18

18-25 Copyright © Oracle Corporation, 2001. All rights reserved.

Signature Mode

• The signature of a procedure is:– The name of the procedure– The datatypes of the parameters– The modes of the parameters

• The signature of the remote procedure is saved inthe local procedure.

• When executing a dependent procedure, thesignature of the referenced remote procedure iscompared.

Page 26: Oracle - Program with PL/SQL - Lession 18

18-26 Copyright © Oracle Corporation, 2001. All rights reserved.

Recompiling a PL/SQLProgram Unit

Recompilation:• Is handled automatically through implicit run-time

recompilation• Is handled through explicit recompilation with the

ALTER statement

Page 27: Oracle - Program with PL/SQL - Lession 18

18-27 Copyright © Oracle Corporation, 2001. All rights reserved.

Unsuccessful Recompilation

Recompiling dependent procedures and functions isunsuccessful 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 28: Oracle - Program with PL/SQL - Lession 18

18-28 Copyright © Oracle Corporation, 2001. All rights reserved.

Successful Recompilation

Recompiling dependent procedures and functions issuccessful 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,

having the same name and structure, exists• The PL/SQL body of a referenced procedure has

been modified and recompiled successfully

Page 29: Oracle - Program with PL/SQL - Lession 18

18-29 Copyright © Oracle Corporation, 2001. All rights reserved.

Recompilation of Procedures

Minimize dependency failures by:• Declaring records by using the %ROWTYPE

attribute• Declaring variables with the %TYPE attribute• Querying with the SELECT * notation• Including a column list with INSERT statements

Page 30: Oracle - Program with PL/SQL - Lession 18

18-30 Copyright © Oracle Corporation, 2001. All rights reserved.

Packages and Dependencies

Page 31: Oracle - Program with PL/SQL - Lession 18

18-31 Copyright © Oracle Corporation, 2001. All rights reserved.

Packages and Dependencies

Page 32: Oracle - Program with PL/SQL - Lession 18

18-32 Copyright © Oracle Corporation, 2001. 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 objectchanges

Page 33: Oracle - Program with PL/SQL - Lession 18

18-33 Copyright © Oracle Corporation, 2001. All rights reserved.

Practice 18 Overview

This practice covers the following topics:• Using DEPTREE_FILL and IDEPTREE to view

dependencies• Recompiling procedures, functions, and packages