🍅Recompile Object Invalid on Oracle

โดยปกติการใช้งาน Data Pump ในการ Import Database ซึ่งส่วนใหญ่จะใช้ในกรณีที่เราต้องการ Data ย้อนหลัง หลังจากที่เราทำการ Import Database เรียบร้อยแล้วจะเกิด Object Invalid ตามมา ได้แก่พวก View, Schema ทำให้เราต้องทำการ Recompile Object ถึงจะสามารถใช้งานได้

Get Started

  • ทำการ Connect Database ด้วย SQL*Plus

$
sqlplus / as sysdba

Solution 1 ( กรณีที่มี Object Invalid ไม่เยอะ )

  • ทำการตรวจสอบ Object Status

SQL>
select object_name, status from dba_objects where object_type = 'VIEW' and status = 'INVALID' ;
  • ทำการ Recompile Object Invalid

SQL>
alter view view_name compile ;

Solution 2 ( กรณีที่มี Object Invalid เยอะ )

  • ทำการตรวจสอบ Object Status โดยใช้ SPOOL ในการ Export Command & Result

SQL>
spool script.sql 
SQL>
select ' alter view ' || object_name || ' compile ' from dba_objects where object_type = 'VIEW' and status like 'INVALID' ;
  • ทำการแก้ไขไฟล์ script.sql ให้เหลือกแต่คำสั่ง Recompile Object Invalid

$
vi script.sql
alter view view_name compile ;
alter view view_name compile ;
alter view view_name compile ;
  • ทำการรัน SQL Script

SQL>
@/home/oracle/script.sql

อ่านเพิ่มเติม : https://bit.ly/2zqc34z

Last updated

Was this helpful?