1. 程式人生 > >檢視PL/SQL編譯時的錯誤資訊

檢視PL/SQL編譯時的錯誤資訊

               

    編譯無效物件是DBA與資料庫開發人員常見的工作之一。對於編譯過程中的錯誤該如何去捕獲,下面給出兩種捕獲錯誤的方法。

一、當前資料庫版本資訊及無效物件

    1、檢視當前資料庫版本   

SQL> select * from v$version;                                                                                                         BANNER                                                             ----------------------------------------------------------------   
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi   PL/SQL Release 10.2.0.4.0 - Production                             CORE    10.2.0.4.0      Production                                 TNS for Solaris: Version 10.2.0.4.0 - Production                   NLSRTL Version 10.2.0.4.0 - Production                            

    2、獲得資料庫中的無效物件

set linesize 180                                                                                        col object_name format a45                                                                              SELECT owner, object_name, object_type, status                                                          FROM
dba_objects                                                                                        WHERE status = 'INVALID'                                                                                     AND                                                                                                     object_type IN ('PROCEDURE', 'FUNCTION', 'TRIGGER', 'VIEW', 'PACKAGE');                                                                                                                                    OWNER                          OBJECT_NAME                                   OBJECT_TYPE         STATUS ------------------------------ --------------------------------------------- ------------------- -------OTC_WRHS_POSITION              OTC_WRHS_POSITION_PCK_tmp                     PACKAGE             INVALID

    3、編譯無效物件(編譯方法很多,在此不一一列出)    

/**************************************************/                          /* Author: Robinson Cheng                         */                          /* Blog:   http://blog.csdn.net/robinson_0612     */                          /* MSN:    [email protected]              */                          /* QQ:     645746311                              */                          /**************************************************/                                                                                                         --注意該包物件中包體的名字含小寫字元,因此編譯時使用雙引號括起來                SQL> alter package "OTC_WRHS_POSITION"."OTC_WRHS_POSITION_PCK_tmp" compile body;

二、捕獲編譯錯誤
    1、使用show errors捕獲錯誤   

SQL> show errors;                                                               No errors.                                                                                                                                                      SQL> show errors package body "OTC_WRHS_POSITION"."OTC_WRHS_POSITION_PCK_tmp";  No errors.                                                                      

    2、如果使用show errors無法查詢到錯誤,直接查詢檢視dba_errors   

SQL> desc dba_errors;                                                                                                   Name           Type           Nullable Default Comments                                                                 -------------- -------------- -------- ------- ---------------------------------------------------------------          OWNER          VARCHAR2(30)                                                                                             NAME           VARCHAR2(30)                    Name of the object                                                       TYPE           VARCHAR2(12)   Y                Type: "TYPE", "TYPE BODY", "VIEW", "PROCEDURE", "FUNCTION",              "PACKAGE", "PACKAGE BODY", "TRIGGER",                                                                                   "JAVA SOURCE" or "JAVA CLASS"                                                                                           SEQUENCE       NUMBER                          Sequence number used for ordering purposes                               LINE           NUMBER                          Line number at which this error occurs                                   POSITION       NUMBER                          Position in the line at which this error occurs                          TEXT           VARCHAR2(4000)                  Text of the error                                                        ATTRIBUTE      VARCHAR2(9)    Y                                                                                         MESSAGE_NUMBER NUMBER         Y                                                                                                                                                                                                                 SQL> select owner,name,TEXT from dba_errors where owner='OTC_WRHS_POSITION' and name='OTC_WRHS_POSITION_PCK_tmp' and      2  sequence=(select max(sequence) from dba_errors where owner='OTC_WRHS_POSITION');                                                                                                                                                           OWNER                NAME                      TEXT                                                                     -------------------- ------------------------- ------------------------------------------------------------             OTC_WRHS_POSITION    OTC_WRHS_POSITION_PCK_tmp PLS-00103: Encountered the symbol "ULL" when expecting one o                                                            f the following:                                                                                                                                                                                                                                   . ( ) , * @ % & = - + < / > at in is mod remainder not re                                                            m                                                                                                                          <an exponent (**)> <> or != or ~= >= <= <> and or like LI                                                            KE2_                                                                                                                       LIKE4_ LIKEC_ between || multiset member SUBMULTISET_                                                                The symbol "." was substituted for "ULL" to continue.