Oracle-为什么我应该使用软件包而不是独立的过程或函数 [英] Oracle - Why should I use packages instead of standalone procedures or functions

查看:45
本文介绍了Oracle-为什么我应该使用软件包而不是独立的过程或函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了google,但没有找到关于我为什么要使用软件包的令人满意的答案.

I searched google but did not find any satisfying answer as to why I should use packages.

我知道一个程序包是一组过程,函数和不同的变量.据我了解,它与OOP中的对象相对应.但是,当然没有什么比实例化包的不同实例更重要的了,每个实例将具有不同的属性值并具有不同的行为.

I know that a package is a bundle of procedures, functions and different variables. As I understand it sort of corresponds to object in OOP. But of course there's nothing like instantiating different instances of a package so that each instance would have different property values and behave differently.

那么当我可以创建一个独立的过程并独立调用它时,使用软件包的好处是什么?

Then what is the advantage of using packages when I can just create a standalone procedure and call it independently?

推荐答案

包具有以下优点:

    凝聚力:与特定子系统有关的所有过程和功能都在一个程序单元中.这只是良好的设计习惯,但也易于管理,例如在源代码管理中.
  1. 常量,子类型和其他有用的东西:PL/SQL比存储过程要重要的多.我们在程序包规范中可以定义的任何内容都可以与其他程序共享,例如用户定义的异常.
  2. 重载:能够使用相同的名称但具有不同的签名来定义过程或函数.
  3. 安全性:在程序包主体中定义私有过程,由于该私有过程未在规范中公开,因此只能由该程序包使用.
  4. 共享通用代码:私有过程的另一个好处.
  5. 我们只需要在一个软件包上授予EXECUTE权限,而不是在多个过程上授予权限.
  1. Cohesion: all the procedures and functions relating to a specfic sub-system are in one program unit. This is just good design practice but it's also easier to manage, e.g. in source control.
  2. Constants, sub-types and other useful things: there's more to PL/SQL than stored procedures. Anything we can define in a package spec can be shared with other programs, for instance user-defined exceptions.
  3. Overloading: the ability to define a procedure or function with the same name but different signatures.
  4. Security: defining private procedures in the package body which can only be used by the package because they aren't exposed in the specification.
  5. Sharing common code: another benefit of private procedures.
  6. We only need to grant EXECUTE on a package rather than on several procedures.

这篇关于Oracle-为什么我应该使用软件包而不是独立的过程或函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆