当前位置:   article > 正文

修改表结构,相关视图、函数和存储过程失效

数据表字段更改会影响视图连接失败吗

例如:

  将表中的字段类型NUMBER(19,2)修改成NUMBER(19,4),这时相关的视图、函数和存储过程会失效,导致无法引用

解决方案:

1、直接找到相应的视图、函数或存储过程,重新编译。

2、通过sql查询相关的视图、函数或存储过程,批量编译

  1. select 'ALTER ' || OBJECT_TYPE || ' ' || owner || '.' || OBJECT_NAME ||
  2. ' COMPILE;'
  3. from all_objects
  4. where status = 'INVALID'
  5. and object_type in ('PACKAGE', 'FUNCTION', 'PROCEDURE', 'TABLE', 'VIEW',
  6. 'SEQUENCE', 'TRIGGER');
  7. select 'ALTER PACKAGE ' || OWNER || '.' || OBJECT_NAME || ' COMPILE body;'
  8. from ALL_objects
  9. where status = 'INVALID'
  10. and object_type in ('PACKAGE BODY');
  11. ----------将查询出来的结果执行下就可以了。。

3、使用存储过程重新编译非法过程、函数、包头、包体、视图、触发器:

  1. create or replace procedure RECOMPILEALLINVALIDOBJECTS as
  2. --重新编译所有非法的对象
  3. cursor c_invalidproc is
  4. select object_type,object_name
  5. from user_objects
  6. where status='INVALID'
  7. and object_type in ('PROCEDURE','FUNCTION','TRIGGER','PACKAGE','PACKAGE BODY','VIEW')
  8. order by object_type;
  9. s_sql varchar2(1000);
  10. s_objecttype user_objects.object_type%TYPE;
  11. s_objectname user_objects.object_name%TYPE;
  12. ct number(8);
  13. runs number(8);
  14. begin
  15. dbms_output.enable(20000);
  16. ct := 0;
  17. loop
  18. open c_invalidproc;
  19. ct := ct+1;
  20. runs := 0;
  21. loop
  22. fetch c_invalidproc into s_objecttype,s_objectname;
  23. exit when c_invalidproc%notfound;
  24. runs := runs+1;
  25. if s_objecttype='PACKAGE' then
  26. s_sql := 'alter PACKAGE '||s_objectname||' compile PACKAGE';
  27. elsif s_objecttype='PACKAGE BODY' then
  28. s_sql := 'alter PACKAGE '||s_objectname||' compile BODY';
  29. else
  30. s_sql := 'alter '||s_objecttype||' '||s_objectname||' compile';
  31. end if;
  32. dbms_output.put('RUN "'||s_sql||'" ');
  33. << RECOMPILE_INVALID_OBJECT >>
  34. begin
  35. execute immediate s_sql;
  36. dbms_output.put_line(' SUCCESS');
  37. exception when others then
  38. dbms_output.put_line(' ERROR!!!');
  39. end RECOMPILE_INVALID_OBJECT;
  40. end loop;
  41. close c_invalidproc;
  42. exit when (runs=0 or ct>10);
  43. end loop;
  44. if runs>0 then
  45. dbms_output.put_line('以下对象仍然是非法的!');
  46. open c_invalidproc;
  47. loop
  48. fetch c_invalidproc into s_objecttype,s_objectname;
  49. exit when c_invalidproc%notfound;
  50. dbms_output.put_line(s_objecttype||' '||s_objectname);
  51. end loop;
  52. close c_invalidproc;
  53. end if;
  54. end;

  注:以上程序源自:http://www.dataguru.cn/thread-139510-1-1.html

且只能处理引用结构在两层的情况中的程序

  

 

转载于:https://www.cnblogs.com/su1643/p/6256586.html

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号