编译无效对象是DBA与数据库开发人员常见的工作之一。对于编译过程中的错误该如何去捕获,下面给出两种捕获错误的方法。
一、当前数据库版本信息及无效对象
1、查看当前数据库版本
[sql] view plain copy
print?
1.SQL> select * from v$version;
2.
3.BANNER
4.----------------------------------------------------------------
5.Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
6.PL/SQL Release 10.2.0.4.0 - Production
7.CORE 10.2.0.4.0 Production
8.TNS for Solaris: Version 10.2.0.4.0 - Production
9.NLSRTL Version 10.2.0.4.0 - Production
2、获得数据库中的无效对象
[sql] view plain copy
print?
1.set linesize 180
2.col object_name format a45
3.SELECT owner, object_name, object_type, status
4.FROM dba_objects
5.WHERE status = 'INVALID'
6. AND
7. object_type IN ('PROCEDURE', 'FUNCTION', 'TRIGGER', 'VIEW', 'PACKAGE');
8.
9.OWNER OBJECT_NAME OBJECT_TYPE STATUS
10. ------------------------------ --------------------------------------------- ------------------- -------
11. OTC_WRHS_POSITION OTC_WRHS_POSITION_PCK_tmp PACKAGE INVALID
3、编译无效对象(编译方法很多,在此不一一列出)
[sql] view plain copy
print?
1./**************************************************/
2./* Author: Robinson Cheng */
3./* Blog: http://blog.csdn.net/robinson_0612 */
4./* MSN: robinson_0612@hotmail.com */
5./* QQ: 645746311 */
6./**************************************************/
7.
8.--注意该包对象中包体的名字含小写字符,因此编译时使用双引号括起来
9.SQL> alter package "OTC_WRHS_POSITION"."OTC_WRHS_POSITION_PCK_tmp" compile body;
二、捕获编译错误
1、使用show errors捕获错误
[sql] view plain copy
print?
1.SQL> show errors;
2.No errors.
3.
4.SQL> show errors package body "OTC_WRHS_POSITION"."OTC_WRHS_POSITION_PCK_tmp";
5.No errors.
2、如果使用show errors无法查询到错误,直接查询视图dba_errors
[sql] view plain copy
print?
1.SQL> desc dba_errors;
2.Name Type Nullable Default Comments
3.-------------- -------------- -------- ------- ---------------------------------------------------------------
4.OWNER VARCHAR2(30)
5.NAME VARCHAR2(30) Name of the object
6.TYPE VARCHAR2(12) Y Type: "TYPE", "TYPE BODY", "VIEW", "PROCEDURE", "FUNCTION",
7."PACKAGE", "PACKAGE BODY", "TRIGGER",
8."JAVA SOURCE" or "JAVA CLASS"
9.SEQUENCE NUMBER Sequence number used for ordering purposes
10. LINE NUMBER Line number at which this error occurs
11. POSITION NUMBER Position in the line at which this error occurs
12. TEXT VARCHAR2(4000) Text of the error
13. ATTRIBUTE VARCHAR2(9) Y
14. MESSAGE_NUMBER NUMBER Y
15.
16. SQL> select owner,name,TEXT from dba_errors where owner='OTC_WRHS_POSITION' and name='OTC_WRHS_POSITION_PCK_tmp' and
17. 2 sequence=(select max(sequence) from dba_errors where owner='OTC_WRHS_POSITION');
18.
19. OWNER NAME TEXT
20. -------------------- ------------------------- ------------------------------------------------------------
21. OTC_WRHS_POSITION OTC_WRHS_POSITION_PCK_tmp PLS-00103: Encountered the symbol "ULL" when expecting one o
22. f the following:
23.
24. . ( ) , * @ % & = - + < / > at in is mod remainder not re
25. m
26. <an exponent (**)> <> or != or ~= >= <= <> and or like LI
27. KE2_
28. LIKE4_ LIKEC_ between || multiset member SUBMULTISET_
29. The symbol "." was substituted for "ULL" to continue.
30.
来源: http://blog.csdn.net/leshami/article/details/6913026