Oracle - Why should I use packages instead of standalone procedures or functions
As described in Oracle docs, packages are good because of:
- modularity
- easier application design
- information hiding
- added functionality
- better performance
Details on each reason are explained in docs.
Packages provide the following advantages:
- 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.
- 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.
- Overloading: the ability to define a procedure or function with the same name but different signatures.
- Security: defining private procedures in the package body which can only be used by the package because they aren't exposed in the specification.
- Sharing common code: another benefit of private procedures.
- We only need to grant EXECUTE on a package rather than on several procedures.