批量编译 pl/sql 过程

发布于 2024-10-22 06:20:29 字数 129 浏览 3 评论 0原文

当我从开发转向生产或发布变更请求时,我有很多需要编译的包。

现在,我们使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

っ左 2024-10-29 06:20:29

您可以执行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.

二智少女 2024-10-29 06:20:29

通常,当我们在数据库中进行大量更改导致大量对象失效时,重新编译它们的最简单方法是运行 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.

多情癖 2024-10-29 06:20:29

您可以将所有 SQL 放入一个文本文件中并通过以下方式执行:

SQL >  @/path/script.sql

您只需提供要执行的脚本的路径。

You can put all the SQLs in a text file and execute that by:

SQL >  @/path/script.sql

You just need to provide path of script to be executed.

許願樹丅啲祈禱 2024-10-29 06:20:29

我的方法是将所有包脚本复制到一个目录中,然后在该目录中创建一个 sql 脚本来加载所有包,请参见下面的示例。

-- load package specifications
@@package1.pks
@@package2.pks

-- load package bodies
@@package1.pkb
@@package2.pkb

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.

-- load package specifications
@@package1.pks
@@package2.pks

-- load package bodies
@@package1.pkb
@@package2.pkb
临风闻羌笛 2024-10-29 06:20:29

解决此问题的一种方法是按正确的顺序部署代码。

PL/SQL 包本身是包体中代码的 API,包本身并不相互依赖。然而,包主体可能依赖于包,因此如果重新编译包,则存在使引用它的包主体无效的风险。

不幸的是,按此顺序工作的部署很常见:

create or replace Package A ...;
create or replace Package Body A ...;
create or replace Package B ...;
create or replace Package Body B ...;
create or replace Package C ...;
create or replace Package Body C ...;

这会产生副作用,即如果包体 A 中的代码依赖于包 B,那么当(重新)创建包 B 时,它会使包体 A 失效。

正确的顺序对于部署来说:

create or replace Package A ...;
create or replace Package B ...;
create or replace Package C ...;
create or replace Package Body A ...;
create or replace Package Body B ...;
create or replace Package Body C ...;

如果包本身没有发生变化,那么当然根本不需要部署它。

尊重这些方法应该会减少无效对象的数量。

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:

create or replace Package A ...;
create or replace Package Body A ...;
create or replace Package B ...;
create or replace Package Body B ...;
create or replace Package C ...;
create or replace Package Body C ...;

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:

create or replace Package A ...;
create or replace Package B ...;
create or replace Package C ...;
create or replace Package Body A ...;
create or replace Package Body B ...;
create or replace Package Body C ...;

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.

压抑⊿情绪 2024-10-29 06:20:29

首先是包头:

for i in $(ls *.hed); do sqlplus user/password @$i; done

然后是包体:

for i in $(ls *.hed); do sqlplus user/password @$i; done

Package Headers first:

for i in $(ls *.hed); do sqlplus user/password @$i; done

Then package bodies:

for i in $(ls *.hed); do sqlplus user/password @$i; done
桃扇骨 2024-10-29 06:20:29

您可以使用 dba_objects 检查无效对象并使用动态 sql 生成编译语句,例如:

select 'alter ' || object_type || ' ' || owner || '.' || object_name || ' compile;'
from dba_objects
where status = 'INVALID'
and object_type in ('PACKAGE', 'PROCEDURE', 'FUNCTION');

然后您可以将其放入 sql 脚本中。

您还可以查看 utl_recomp 包

you can use dba_objects to check for invalid objects and use dynamic sql to generate compile statements, something like:

select 'alter ' || object_type || ' ' || owner || '.' || object_name || ' compile;'
from dba_objects
where status = 'INVALID'
and object_type in ('PACKAGE', 'PROCEDURE', 'FUNCTION');

you can then put that into a sql script.

You can also look into utl_recomp package

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文