开发时,一般都是使用PL/SQL工具进行开发,查看编译错误及重新编译都很简单,但是一般的生产环境是不允许连接外界工具的,只能在命令行中进行重新编译及查看,今天我就遇到了这个问题,现在总结如下:
1、获取数据库中的无效对象:
set linesize 180;
col owner format a10
col object_name format a45
col object_type format a20
col status format a20
SELECT owner, object_name, object_type, status
FROM dba_objects
WHERE status = 'INVALID'; OWNER OBJECT_NAME OBJECT_TYPE STATUS
---------- --------------------------------------------- -------------------- ------------------
YLPROD DMPAC_ENDOR PACKAGE BODY INVALID
2、编译无效对象
SQL> alter package ylprod.dmpac_endor compile package; 警告: 更改的包带有编译错误。
这是重新编译包体,package是重新编译包体和包规范。
SQL> alter package ylprod.dmpac_endor compile package;
3.捕获编译错误
SQL> show errors;
PACKAGE YLPROD.DMPAC_ENDOR 出现错误: LINE/COL ERROR
-------- -----------------------------------------------------------------
21/3 PL/SQL: Declaration ignored
23/54 PLS-00302: 必须声明 'ENDORNO' 组件
27/3 PL/SQL: Declaration ignored
29/59 PLS-00302: 必须声明 'ENDORNO' 组件
或者
SQL> show errors package ylprod.DMPAC_ENDOR
PACKAGE YLPROD.DMPAC_ENDOR 出现错误: LINE/COL ERROR
-------- -----------------------------------------------------------------
21/3 PL/SQL: Declaration ignored
23/54 PLS-00302: 必须声明 'ENDORNO' 组件
27/3 PL/SQL: Declaration ignored
29/59 PLS-00302: 必须声明 'ENDORNO' 组件
如果使用show errors无法查询到错误,直接查询视图dba_errors
SQL> select owner,name,TEXT from dba_errors where owner='YLPROD' and name='DMPAC_ENDOR'; OWNER NAME
---------- ------------------------------------------------------------------------------------------
TEXT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
YLPROD DMPAC_ENDOR
PLS-00302: 必须声明 'ENDORNO' 组件 YLPROD DMPAC_ENDOR
PL/SQL: Declaration ignored