虚拟化容器,大数据,DBA,中间件,监控。

PL/SQL 批量编译oracle无效视图,程序包,过程

25 11月
作者:admin|分类:DBA运维

利用sqldeveloper4.5工具生成的plsql语句,以供参考。


1,编译无效视图,注意修改变量与对应的账号表名。

begin

  FOR cur IN (SELECT OBJECT_NAME, OBJECT_TYPE, owner
                FROM all_objects
               WHERE object_type = 'VIEW'
                 and owner = 'LWLK'
                 AND status = 'INVALID') LOOP
    BEGIN
      if cur.OBJECT_TYPE = 'PACKAGE BODY' then
        EXECUTE IMMEDIATE 'alter ' || cur.OBJECT_TYPE || ' "' || cur.owner ||
                          '"."' || cur.OBJECT_NAME || '" compile body';
      else
        EXECUTE IMMEDIATE 'alter ' || cur.OBJECT_TYPE || ' "' || cur.owner ||
                          '"."' || cur.OBJECT_NAME || '" compile';
      end if;
    EXCEPTION
      WHEN OTHERS THEN
        NULL;
    END;
  end loop;

end;



2,编译无效程序包,注意修改变量与对应的账号表名。

begin
  FOR cur IN (SELECT OBJECT_NAME, OBJECT_TYPE, owner
                FROM all_objects
               WHERE object_type in ('PACKAGE', 'PACKAGE BODY')
                 and owner = :OBJECT_OWNER
                 AND status = 'INVALID') LOOP
    BEGIN
      if cur.OBJECT_TYPE = 'PACKAGE BODY' then
        EXECUTE IMMEDIATE 'alter package "' || cur.owner || '"."' ||
                          cur.OBJECT_NAME || '" compile body';
      else
        EXECUTE IMMEDIATE 'alter ' || cur.OBJECT_TYPE || ' "' || cur.owner ||
                          '"."' || cur.OBJECT_NAME || '" compile';
      end if;
    EXCEPTION
      WHEN OTHERS THEN
        NULL;
    END;
  end loop;
end;


3, 编译无效过程,注意修改变量与对应的账号表名。

begin
  FOR cur IN (SELECT OBJECT_NAME, OBJECT_TYPE, owner
                FROM all_objects
               WHERE object_type = :OBJECT_FOLDER_TYPE
                 and owner = :OBJECT_OWNER
                 AND status = 'INVALID') LOOP
    BEGIN
      if cur.OBJECT_TYPE = 'PACKAGE BODY' then
        EXECUTE IMMEDIATE 'alter ' || cur.OBJECT_TYPE || ' "' || cur.owner ||
                          '"."' || cur.OBJECT_NAME || '" compile body';
      else
        EXECUTE IMMEDIATE 'alter ' || cur.OBJECT_TYPE || ' "' || cur.owner ||
                          '"."' || cur.OBJECT_NAME || '" compile';
      end if;
    EXCEPTION
      WHEN OTHERS THEN
        NULL;
    END;
  end loop;
end;






浏览1998 评论0
返回
目录
返回
首页
Alter Log中VKTM时间drift漂移现象 Linux 按名称查找某个进程并关闭