oracle DBMS_UTILITY.COMPILE_SCHEMA(schema => '<SCHEMA_NAME>', compile_all => FALSE) 不编译无效的包体
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28815914/
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
DBMS_UTILITY.COMPILE_SCHEMA(schema => '<SCHEMA_NAME>', compile_all => FALSE) doesn't compile invalid package bodies
提问by Toru
The call of
的呼唤
BEGIN
DBMS_UTILITY.COMPILE_SCHEMA(schema => '<SCHEMA_NAME>', compile_all => FALSE);
END;
/
doesn't compile invalid package bodies. Does anybody know the reason?
不编译无效的包体。有人知道原因吗?
(Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production)
(Oracle 数据库 11g 企业版 11.2.0.1.0 版 - 生产)
回答by Alex Poole
It does; at least in 11.2.0.3, so I suppose there could have been a bug in the base release.
确实如此;至少在 11.2.0.3 中,所以我想基本版本中可能存在错误。
if I create an invalid package, in this case because it refers to a table that doesn't exist:
如果我创建了一个无效的包,在这种情况下是因为它引用了一个不存在的表:
create package p42 as
procedure test;
end p42;
/
PACKAGE P42 compiled
create package body p42 as
procedure test is
n number;
begin
select count(*) into n from t42;
end test;
end p42;
/
PACKAGE BODY P42 compiled
Errors: check compiler log
And then check the status and last DDL time:
然后检查状态和上次 DDL 时间:
select object_type, object_name, status, last_ddl_time
from user_objects where object_name = 'P42'
order by object_type, object_name;
OBJECT_TYPE OBJECT_NAME STATUS LAST_DDL_TIME
------------------- -------------------- ------- -------------------
PACKAGE P42 VALID 2015-03-02 17:39:42
PACKAGE BODY P42 INVALID 2015-03-02 17:39:42
And then recompile the schema and check again:
然后重新编译架构并再次检查:
BEGIN
DBMS_UTILITY.COMPILE_SCHEMA(schema => USER, compile_all => FALSE);
END;
/
anonymous block completed
select object_type, object_name, status, last_ddl_time
from user_objects where object_name = 'P42'
order by object_type, object_name;
OBJECT_TYPE OBJECT_NAME STATUS LAST_DDL_TIME
------------------- -------------------- ------- -------------------
PACKAGE P42 VALID 2015-03-02 17:39:42
PACKAGE BODY P42 INVALID 2015-03-02 17:39:49
.. the last DDL time has changed, so it was recompiled. It's still invalid as I haven't fixed the underlying problem. And I can see the
..上次DDL时间变了,所以重新编译了。它仍然无效,因为我还没有解决根本问题。我可以看到
select text from user_errors where name = 'P42';
TEXT
------------------------------------------------------------
PL/SQL: ORA-00942: table or view does not exist
PL/SQL: SQL Statement ignored
Or if your '<SCHEMA_NAME>'
isn't your current user, it will be in all_errors
, if it's still invalid.
或者,如果您'<SCHEMA_NAME>'
不是您当前的用户,它将在 中all_errors
,如果它仍然无效。
If I create the missing table and compile the schema again:
如果我创建丢失的表并再次编译架构:
create table t42 (id number);
Table t42 created.
BEGIN
DBMS_UTILITY.COMPILE_SCHEMA(schema => USER, compile_all => FALSE);
END;
/
anonymous block completed
select object_type, object_name, status, last_ddl_time
from user_objects where object_name = 'P42'
order by object_type, object_name;
OBJECT_TYPE OBJECT_NAME STATUS LAST_DDL_TIME
------------------- -------------------- ------- -------------------
PACKAGE P42 VALID 2015-03-02 17:39:42
PACKAGE BODY P42 VALID 2015-03-02 17:40:11
... the last DDL time has changed again, as has the status now. If I compile again, with your compile_all => FALSE
flag, then the last DDL time won't change as it won't look at the valid package.
... 上次 DDL 时间又发生了变化,现在的状态也是如此。如果我用你的compile_all => FALSE
标志再次编译,那么最后的 DDL 时间不会改变,因为它不会查看有效的包。