快速編譯sql過程和視圖的腳本
2024-07-21 02:40:59
供稿:網友
經常碰到因為過程或者視圖沒有被編譯,,而無法正常運行基于存儲過程的數據庫程序。
用以下幾句sql語句,用于在程序執行之前,自動編譯。省去了我們的麻煩
/***************************************PRo.sql****************************************/
#用于快速編輯過程
set feedback off
set heading off
spool c:/pro.sql;
#編譯過程
select 'alter procedure 'OBJECT_NAME' compile;' from sys.all_probe_objects where OWNER='UserName' and OBJECT_TYPE='PROCEDURE' and STATUS='INVALID';
spool off;
@c:/pro.sql;
#編譯視圖
spool c:/pro.sql;
select 'alter view 'OBJECT_NAME' compile;' from sys.all_probe_objects where OWNER='UserName' and OBJECT_TYPE='view' and STATUS='INVALID';
spool off;
@c:/pro.sql;
exit;
#select * from sys.all_objects where object_type in ('TABLE', 'VIEW' ) and STATUS!='VALID';
/**************************************************pro.bat ******************************************************/
set Oracle_SID=DB_NAME;
sqlplus username/passWord @F:/shell/pro.sql
用于執行,這個sql語句
/*
/**************************************************exec.bat*****************************************************/
加入at 計劃任務
net stop schedule
net start schedule
at 23:00 /every:M,T,W,Th,F,S,SU F:/shell/pro.bat
////////////////////////////////////////////////////////////////////The End ///////////////////////////////////////////////////////////////////////////////////