我在现场作项目,经常会改一些数据库的表或过程,这样就可能造成过程的失效。
我想写一个过程,自动查找oracle数据库失效的过程(包)并编译它,然后放到job
里,每天晚上自动执行。
请问各位高手,有没有这样的东东,给我发一个.
Email:[email protected]
谢谢!
我想写一个过程,自动查找oracle数据库失效的过程(包)并编译它,然后放到job
里,每天晚上自动执行。
请问各位高手,有没有这样的东东,给我发一个.
Email:[email protected]
谢谢!
CREATE OR REPLACE PROCEDURE compile_invalid_procedure
IS
CURSOR c1 IS
SELECT owner,object_name,object_type
FROM dba_objects
WHERE object_type IN ('FUNCTION','PROCEDURE')
AND status='INVALID';
l_c1 c1%ROWTYPE;
str1 VARCHAR2(100);
BEGIN
OPEN c1
LOOP
FETCH c1 INTO TO l_c1;
EXIT WHEN c1%NOTFOUND;
str1:='alter '||l_c1.object_type||' '||l_c1.owner||'.'||l_c1.object_name||' compile';
dbms_utility.exec_ddl_statement(str1);
END LOOP;
CLOSE c1;
END;
查找失效的存储过程到:SYS.USER_OBJECTS或SYS.ALL_OBJECTS中查找。(SYS.USER_PACKAGE和SYS.USER_PACKAGE_BODY)
如果需要在存储过程中编译,首先查找到存储过程(包)的语句,然后生成动态的创建存储过程(包)的语句,调用DBMS_SQL包的有关功能即可。
具体情况可以搜索一下以前的帖子,比如得到语法,DBMS_SQL包的用法等,最好找找有关书籍看一下。
注意:由于我当前没有ORACLE环境,所以不能帮你调试,因此我不能确定ORACLE是否支持动态编译存储过程的功能,也不能说的再详细些,还请原谅。
的变成有效。
谢谢 hrb_qiuyb(大森林),如果可行,一定给分
没有错误的过程,如果有编译错误而实际是正确的
在重新执行的时候,oracle会重新编译。
而有错误的过程,你再编译还是有编译错误。
我用的是8.1.7,如果过程失效,调用时,会报告错误,而不会重新编译呀
过程A仅仅调用过程B,过程C,
过程B,过程C是有效的。而A无效时,仍然是可以执行的.
sys用户下的dbms_utility.compile_schema。
详细说明如下:
procedure compile_schema(schema varchar2, compile_all boolean default TRUE);
-- Compile all procedures, functions, packages and triggers in the specified
-- schema. After calling this procedure you should select from view
-- ALL_OBJECTS for items with status of 'INVALID' to see if all objects
-- were successfully compiled. You may use the command "SHOW ERRORS
-- <type> <schema>.<name>" to see the errors assocated with 'INVALID'
-- objects.
-- Input arguments:
-- schema
-- Name of the schema.
-- compile_all
-- This is a boolean flag that indicates whether we should compile all
-- schema objects or not, regardless of whether the object is currently
-- flagged as valid or not. The default is to support the previous
-- compile_schema() behaviour and compile ALL objects.
-- Exceptions:
-- ORA-20000: Insufficient privileges for some object in this schema.
-- ORA-20001: Cannot recompile SYS objects.
-- ORA-20002: Maximum iterations exceeded.
-- Some objects may not have been recompiled
-- Notes:
-- 1) When this procedure is executed it determines an upper limit to
-- the number of objects that need to be recompiled and then iterates
-- around the objects to be recompiled. Should this upper limit be
-- exceeded then the last exception will be raised and in this case
-- you can just re-execute the procedure again. Should this fail with
-- the same error then this may indicate an object that persistently
-- fails for some reason.
重新测试了一下,还是会自动重新编译。
如我有一个过程sp_check_error,是正确的有效的,
它要操作t_error表,我先表表t_error改名,
然后查看sp_check_error,发现过程是失效的。
然后我把表改回来,这时候过程还是失效的。我在sql plus下
exec sp_check_error,系统说过程成功执行,再检查过程,是有效的。
oracle 805,os win2000 server
我以前在所有的系统上发现在执行时如果有编译错误都应当是自动重新编译的,包括视图,触发器,包都一样。难道你们不是这样???