批量编译 pl/sql 过程
当我从开发转向生产或发布变更请求时,我有很多需要编译的包。
现在,我们使用 toad 或 sqldbx 逐一编译每个包,有没有一种方法可以使用 sqlplus 命令编写批处理文件,以便我可以一次性运行所有包.. 就像 *.sql
i have lots of packages which needed to be compiled when i move from development to production or when we release a change request.
right now , we compile each of the packages one by one using toad or sqldbx , is there a way that i can write a batch file with sqlplus command so that i can run all my packages in one go.. like *.sql
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可以执行
dbms_utility.compile_schema(user,false);
来一次性编译模式中的所有无效对象。您可以在文档中阅读有关该过程的信息: http://download.oracle.com/docs/cd/E11882_01/appdev.112/e16760/d_util.htm#ARPLS73226
问候,
抢。
You can execute
dbms_utility.compile_schema(user,false);
to compile all invalid objects in your schema at once.You can read about that procedure here in the documentation: http://download.oracle.com/docs/cd/E11882_01/appdev.112/e16760/d_util.htm#ARPLS73226
Regards,
Rob.
通常,当我们在数据库中进行大量更改导致大量对象失效时,重新编译它们的最简单方法是运行 sqlplus "/ as sysdba" @?/rdbms/admin/utlrp 此过程得到每个版本都更加智能,从 10g 开始,它使用 Oracle Scheduler 并行工作。当然,这仅适用于 dba 访问数据库的情况。如果您缺乏这一点,罗布·范韦克的答案就是您的最佳选择。
Normally when we do lots of changes in a database that invalidates lots of objects, the easiest way to get them recompiled is by running
sqlplus "/ as sysdba" @?/rdbms/admin/utlrp
This procedure gets smarter every release and from 10g it uses the Oracle Scheduler to work in parallel. This of course only works with dba access to the database. If you lack that Rob van Wijk's answer is the way to go.您可以将所有 SQL 放入一个文本文件中并通过以下方式执行:
您只需提供要执行的脚本的路径。
You can put all the SQLs in a text file and execute that by:
You just need to provide path of script to be executed.
我的方法是将所有包脚本复制到一个目录中,然后在该目录中创建一个 sql 脚本来加载所有包,请参见下面的示例。
My approach would be to copy all package scripts into a directory then create a single sql script in that directory to load all packages, see example below.
解决此问题的一种方法是按正确的顺序部署代码。
PL/SQL 包本身是包体中代码的 API,包本身并不相互依赖。然而,包主体可能依赖于包,因此如果重新编译包,则存在使引用它的包主体无效的风险。
不幸的是,按此顺序工作的部署很常见:
这会产生副作用,即如果包体 A 中的代码依赖于包 B,那么当(重新)创建包 B 时,它会使包体 A 失效。
正确的顺序对于部署来说:
如果包本身没有发生变化,那么当然根本不需要部署它。
尊重这些方法应该会减少无效对象的数量。
One way of tackling this is to deploy your code in the correct order.
PL/SQL packages themselves are the API for the code in the package body, and the packages themselves are not dependent on each other. Package bodies however can be dependent on packages, so if a package is recompiled than it runs the risk of invalidating package bodies that reference it.
Unfortunately it's very common to see deployments that work in this order:
This has the side-effect that if code in Package Body A is dependent on Package B, then when Package B is (re)created it invalidates Package Body A.
The correct sequence for deployment is:
If there have not been changes in the package itself then there is no need to deploy it at all, of course.
Respecting these methods should give you much fewer invalid objects.
首先是包头:
然后是包体:
Package Headers first:
Then package bodies:
您可以使用 dba_objects 检查无效对象并使用动态 sql 生成编译语句,例如:
然后您可以将其放入 sql 脚本中。
您还可以查看 utl_recomp 包
you can use dba_objects to check for invalid objects and use dynamic sql to generate compile statements, something like:
you can then put that into a sql script.
You can also look into utl_recomp package