Is there Any way to compile only one particular pa

2019-06-10 09:47发布

Oracle server is not so smart to catch updated packages. so whenever I recompile my package. it throws existing package invalidate error.

if is there any way so that I can refresh only my package on server. So I don't need to bounce server and stop server which is used by everyone.

标签: oracle10g
2条回答
冷血范
2楼-- · 2019-06-10 10:04

If you modified the package (let's call it PKG_TEST), both specification and body, it is compiled with

alter package pkg_test compile;

If specification was changed, it might have caused other dependent objects to become invalid (that's probably what you saw).

However, if you modify only package body, you don't have to compile specification (as it didn't change) but only body:

alter package pkg_test compile body;

Whatever changes you did to the body, they won't invalidate other objects. So, pick one of those commands, depending on what you did to that package.

查看更多
该账号已被封号
3楼-- · 2019-06-10 10:11
  1. Minimize public functions, procedures, and variables. Invalid objects and ORA-04068: existing state of packages has been discarded errors will decrease after minimizing public objects and minimizing the package state.

    Any function or procedure in a package specification is public. Changing those functions and procedures may change the way other objects use the package, causing invalidations. Also, public APIs should be thoroughly documented and tested. Which means you want to have as few public APIs as possible. For some reason most Oracle programs unnecessarily put all their procedures and functions in the specification, when most of them are only needed in the body. This change will make your programs better, shrink dependencies, and minimalize invalid objects.

    Any variable in the package specification is also public, and will maintain its value for the duration of the session. As in any language, public variables should also be minimized. For some reason most Oracle programs also unnecessarliy put many variables in the specification, instead of the body. If there are no variables in the specification, there is no package state and you won't see ORA-04068.

  2. Do not develop on shared systems. Give every developer an infinite number of databases and merge changes in version-controlled text files. There are many easy and cheap ways to get an infinite number of databases - databases installed locally, virtual machines, containers, etc. There are also many easy and cheap ways to version control text files - every modern IDE can open and save files to the filesystem, then use something like Git or SVN.

    Having multiple developers work on a single shared system simply does not scale. Other than "it was slightly easier to set it up that way", there is literally no good reason to develop that way anymore.

  3. Compile body, not specification. As Littlefoot suggested, try to change the body instead of the specification. (Although dependencies were less granular in 10g, this may not help as much as it would in modern versions.)

查看更多
登录 后发表回答