替换 Oracle 包的一部分
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3652398/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Replacing part of an Oracle package
提问by Robert Munteanu
I need to modify one procedure from within a package. I need to touch both the declaration and the implementation. As I am maintaining patch files for each modification, I would like the changes to be minimal.
我需要从一个包中修改一个过程。我需要触及声明和实现。当我为每次修改维护补丁文件时,我希望更改最小。
Can I update the package with just the changed procedure ( if yes, how ? ) , or do I need to supply the complete package definition and implementation?
我是否可以仅使用更改后的程序更新包(如果是,如何更新?),还是需要提供完整的包定义和实现?
回答by Tony Andrews
You need to replace the whole package specification and body - you cannot operate on just part of a package.
您需要替换整个包规范和正文 - 您不能仅对包的一部分进行操作。
回答by JulesLt
Just to contradict everyone else . . .
只是为了反驳其他人。. .
Technically you could do it - you could write something that would take in your patch file, retrieve the existing package source from the database (using USER_SOURCE), apply your patch, and then recompile the package using EXECUTE IMMEDIATE.
从技术上讲,您可以做到这一点 - 您可以编写一些可以包含在补丁文件中的内容,从数据库中检索现有的包源(使用 USER_SOURCE),应用您的补丁,然后使用 EXECUTE IMMEDIATE 重新编译包。
However, I don't think it would be a very good idea - patch based fixing becomes very difficult to keep track of, especially once multiple patches and multiple databases are involved. Putting the whole file into source control is a lot better - your patch should still be clearly visible.
但是,我认为这不是一个好主意——基于补丁的修复变得非常难以跟踪,尤其是在涉及多个补丁和多个数据库时。将整个文件放入源代码管理中会好得多 - 您的补丁应该仍然清晰可见。
If the patch is to a third-party package, consider wrapping it - so that everything is a straight call through except your patch. Or put your patch into a standalone package that calls the first one. There is still a danger that a change to the original package could be incompatible with your patch.
如果补丁是针对第三方软件包的,请考虑对其进行包装 - 这样除了您的补丁之外,所有内容都可以直接调用。或者将您的补丁放入调用第一个的独立包中。仍然存在对原始软件包的更改可能与您的补丁不兼容的危险。
回答by Kirill Leontev
You cannot. As far as I remember, the only way to avoid referencing objects invalidation is not to touch your package declaration, and perform only CREATE OR REPLACE PACKAGE BODY
.
你不能。据我所知,避免引用对象失效的唯一方法是不要触及您的包声明,并且只执行CREATE OR REPLACE PACKAGE BODY
.
回答by Erich Kitzmueller
Since the declaration changes, you might consider putting the new procedure into a new package, to avoid touching the existing one. Packages using the new version of the procedure must be adapted anyways, to reflect the change in the declaration (unless it's a new parameter with a default value).
由于声明发生变化,您可能会考虑将新程序放入一个新包中,以避免触及现有程序包。无论如何,必须对使用新版本过程的包进行调整,以反映声明中的更改(除非它是具有默认值的新参数)。
回答by Jeffrey Kemp
If you're on Oracle 11g, and you want to minimise invalidations of other objects, make sure to place the new declarations at the endof the package spec.
如果您使用的是 Oracle 11g,并且希望最大限度地减少其他对象的失效,请确保将新声明放在包规范的末尾。