如何获取 Oracle 10g 中无效对象的错误列表

How to fetch the list of errors for invalid objects in Oracle 10g

说明:我的数据库中有 200 多个无效对象,原因可能只是几个对象(其他是由于依赖)。有没有办法我们可以 select 对象名称和 'Error Reason' 因为它是无效的。

您可以查询[DBA/ALL/USER]_ERRORS。它描述了当前用户拥有的所有存储对象(视图、过程、函数、包和包体)的当前错误。

根据您拥有的权限选择要查询的视图:

  • DBA_ : All objects in the database
  • ALL_ : All objects owned by the user and on which the user has been granted privileges
  • USER_ : All objects owned by the user

例如,

我创建了一个过程,有一个编译错误,我想查询错误详细信息:

SQL> CREATE OR REPLACE PROCEDURE p
  2  BEGIN
  3  NULL
  4  END;
  5  /

Warning: Procedure created with compilation errors.

SQL>
SQL> SELECT NAME, TYPE, line, text FROM user_errors;

NAME  TYPE             LINE TEXT
----- ---------- ---------- --------------------------------------------------
P     PROCEDURE           2 PLS-00103: Encountered the symbol "BEGIN" when exp
                            ecting one of the following:

                               ( ; is with authid as cluster compress order us
                            ing compiled
                               wrapped external deterministic parallel_enable
                            pipelined
                               result_cache accessible


SQL>

在文档中阅读更多相关信息 here

您可以查看此视图​​:

SELECT OWNER, OBJECT_NAME, OBJECT_TYPE, STATUS
FROM ALL_OBJECTS
WHERE STATUS <> 'VALID';

分别。 USER_OBJECTSDBA_OBJECTS.

ALL_ERRORS 不显示所有无效对象。

示例:

CREATE TABLE tt (a NUMBER);
CREATE OR REPLACE VIEW ttt AS SELECT * FROM tt;
DROP TABLE tt;

SELECT * FROM USER_ERRORS;

no rows selected.

但是,一旦您获得条目后选择视图:

SELECT * FROM ttt;

Error at line 1
ORA-04063: view "xxxx.TTT" has errors

SELECT NAME, TYPE, TEXT FROM USER_ERRORS;

NAME    TYPE    TEXT
--------------------------------------------------------
TTT     VIEW    ORA-00942: table or view does not exist