Can someone tell me, why we package Spec is required in oracle PL/SQL. anyway the package body has all the information as spec.
相关问题
- Can I skip certificate verification oracle utl_htt
- Can I skip certificate verification oracle utl_htt
- how to calculate sum time with data type char in o
- keeping one connection to DB or opening closing pe
- System.Data.OracleClient not working with 64 bit O
相关文章
- node连接远程oracle报错
- oracle 11g expdp导出作业调用失败,提示丢包。
- 执行一复杂的SQL语句效率高,还是执行多少简单的语句效率高
- Oracle equivalent of PostgreSQL INSERT…RETURNING *
- Difference between FOR UPDATE OF and FOR UPDATE
- Oracle USING clause best practice
- Is there a method in PL/SQL to convert/encode text
- PHP PDO installation on windows (xampp)
The package specification contains the definition or specification of all the publicly available elements in the package that may be referenced outside of the package. The specification is like one big declaration section; it does not contain any PL/SQL blocks or executable code. If a specification is well designed, a developer can learn from it everything necessary to use the package. There should never be any need to go “behind” the interface of the specification and look at the implementation,which is in the body.
The distinction drawn between public and private elements in a package gives PL/SQL developers unprecedented control over their data structures and programs. As Booch diagram below displays Notice the two labels Inside and Outside. Outside consists of all the programs you write that are not a part of the package at hand (the external programs). Inside consists of the package body (the internals or implementation of the package).
Here are the conclusions we can draw from the Booch diagram:
This explanation is inspired by oracle pl/sql programming 5th edition by Steven Feuerstein
The separation of package Specification from the package Body is a fundamentally important part of the design of languages such as PL/SQL. It's the way that PL/SQL allows you to use the principle of Encapsulation.
The Specification is the way you specify the Public portion of the package, that is, the functions, procedures, types and constants that should be accessible by other program units or external callers.
The Body not only encapsulates the implementation details, but also allows you to create functions and procedures that are Private; that is, they are only allowed to be used by other functions and procedures in the same package, and cannot be called by external callers.
Encapsulation brings a number of benefits - including self-documentation: if a method is Private, you are guaranteed that there will be no calls to it except within the same package - so you are free to change it, secure in the knowledge that your change will at least not break any other system that uses the package.
Packages are useful as APIs; the specification then becomes the documentation of which functions and procedures are designed and intended to be called by other code in the system.