PL/SQL高级-Creating Packages (00)

Objectives

After completing this lesson,you should be able to do the following

  • Describe packages and list their components
  • Create a package to group together related variables,cursors,constants,exceptions,procedures,and fuctions.
  • Designate a package construct as either public or private
  • Invoke a package construct
  • Describe the use of a bodiless package

Lesson Agenda

  • Identifying the benefits and the components of packages
  • Working with packages
    • -Creating the package specification and body
    • -Invoking the package subprograms
    • -Removing a package
    • -Displaying the package information

What Are PL/SQL Packages?

  • A package is a schema object that groups logically related PL/SQL types,variables,and subprograms.
  • Packages usually have two parts:
    • -A specification(spec)
    • -A body
  • The specification is the interface to the package.It declare the types,variables,constants,exceptions,cursors,and subprograms that can be referenced from outside the package.
  • The body defines the queries for the cursors and the code for the subprograms.
  • Enable the Oracle server to read multiple objects into memory at once.

Advantages of Using Packages

  • Modularity:Encapsulating related constructs
  • Easier maintenance:Keepling logically related functionality together
  • Easier apllication design:Coding and compiling the specification and body separately
  • Hiding information:
    • Only the declarations  in the package sepcification are visible and accessible to applications.
    • Private constructs in the package body are hidden and inaccessible.
    • All coding is hidden in the package body
  • Added functionality:Persistency of public variables and cursors
  • Better performance:
    • -The entire package is loaded into memory when the package is first referenced.
    • -The is only one copy in memory for all users
    • -The dependency hierarchy is simplified.
  • Overloading:Multiple subprograms of the same name
  • The package is a powerful and important element of the PL/SQL language.It should be the cornerstone of any application development project.
  • Always construct your application around packages;avoid standlone procedure and fuctions.Even if tody you think that only one procedure is needed for a certain area of functionality,in the future you will almost certainly have two,then three,and then a dozen.At which point,you will find yourself saying,"Gee,I should really collect those together in a package!" That`s fine,except that now you have to go back to all the invocations of those unpackaged procedures and functions and add in the package prefix.So start wit a package and save yourself the trouble.
posted @ 2013-04-27 11:53  ArcerZhang  阅读(136)  评论(0编辑  收藏  举报