Oracle編譯使用者無效對象

來源:互聯網
上載者:User

Oracle編譯使用者無效對象

在採用IMPDP/IMP工具遷移資料時,經常會提示無效對象的警告,需要採用如下方式處理。

1. 查詢指定使用者的無效對象

su – Oracle

sqlplus / as sysdba

SQL> select owner,object_name,replace(object_type,' ','') object_type,to_char(created,'yyyy-mm-dd') as created,to_char(last_ddl_time,'yyyy-mm-dd') as last_ddl_time,status from dba_objects where status='INVALID' and owner='HKJJW'; 
OWNER      OBJECT_NAME                    OBJECT_TYPE    CREATED    LAST_DDL_T STATUS   
---------- ------------------------------ --------------- ---------- ---------- -------   
HKJJW      FUNC_RETURN_PY                FUNCTION        2013-08-02 2013-08-02 INVALID   
HKJJW      MONITORING_FLOW_PARALLEL_VIEW  VIEW            2013-08-02 2013-08-02 INVALID   
HKJJW      TEST                          VIEW            2013-08-02 2013-08-02 INVALID

指定查詢某使用者無效對象。

SQL> select * from dba_objects where status<>'VALID' and owner='HKJJW';

2. 手動執行編譯或

ALTER FUNCTION HKJJW.FUNC_RETURN_PY COMPILE; 
ALTER VIEW HKJJW.MONITORING_FLOW_PARALLEL_VIEW COMPILE;   
ALTER VIEW HKJJW.TEST COMPILE;

如果是index的話,需要重建. 
alter index index_name rebuild;

如果是package body 
alter package DBMS_CUBE  compile body;

3. 自動產生編譯無效對象SQL

1) 統計目前使用者無效對象數量:

SQL> select owner,object_type,status,count(*) from dba_objects where status='INVALID' group by owner,object_type,status order by owner,object_type;

OWNER                          OBJECT_TYPE        STATUS    COUNT(*) 
------------------------------ ------------------- ------- ----------   
HNADEV_GROUP                  FUNCTION            INVALID          1   
HNADEV_GROUP                  PACKAGE BODY        INVALID        35   
HNADEV_GROUP                  VIEW                INVALID          7

2) 產生編譯無效對象SQL

SQL> select  'ALTER ' || OBJECT_TYPE || ' ' ||  OWNER || '.' || OBJECT_NAME || ' COMPILE;' from dba_objects where status = 'INVALID' and object_type in ('PACKAGE','PACKAGE BODY','FUNCTION','PROCEDURE','TRIGGER','VIEW') ;

'ALTER'||OBJECT_TYPE||''||OWNER||'.'||OBJECT_NAME||'COMPILE;' 
----------------------------------------------------------------------   
ALTER VIEW HNADEV_GROUP.V_E_T_FEEMONTH_CAL COMPILE;   
ALTER VIEW HNADEV_GROUP.V_E_T_FEEMONTH COMPILE;   
ALTER VIEW HNADEV_GROUP.V_E_Z_BILL_STAY_GROUP COMPILE;   
略...   
通過複製以上SQL語句,直接手動執行編譯執行.

4. 也可以採用如下方式在oracle使用者下進行手工編譯

# su - oracle 
$ sqlplus / as sysdba   
SQL> @$ORACLE_HOME/rdbms/admin/utlrp.sql

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.