lunes, 7 de abril de 2014

Script para Compilar los Trigger, Funciones, Proc., Paquetes...

MIÉRCOLES, 19 DE MARZO DE 2014

hola,
este dia he tenido que realizar una actividad para verificar y compilar todos los trigger de una base de datos oracle 12c, para lo cual cree un script basado en el contenido de la tabla sys.dba_objects, pero me surgio una duda??......
como puedo compilar las vistas, trigger, definicion de paquetes, cuerpos de paquetes, procedimientos de una sola vez..

para este caso he creado el siguiente script que espero les sea de utilidad, no olvides dejar tus comentarios

set serveroutput on size 9999
begin
for c1 in (select  CASE
        WHEN  object_type='TRIGGER'     THEN  'ALTER TRIGGER '||owner||'.'||object_name||' COMPILE'
        WHEN object_type='PROCEDURE' THEN  'ALTER PROCEDURE '||owner||'.'||object_name||' COMPILE'
        WHEN  object_type='FUNCTION'   THEN  'ALTER FUNCTION '||owner||'.'||object_name||' COMPILE'
        WHEN  object_type='VIEW'          THEN  'ALTER VIEW '||owner||'.'||object_name||' COMPILE' 
        WHEN  object_type='PACKAGE'       THEN  'ALTER PACKAGE '||owner||'.'||object_name||' COMPILE'
        WHEN  object_type='PACKAGE BODY'       THEN  'ALTER PACKAGE '||owner||'.'||object_name||' COMPILE BODY'
        END sqltext,
        object_type,
        object_name,
        owner
from dba_objects
where object_type IN ( 'TRIGGER' , 'PROCEDURE', 'FUNCTION', 'VIEW','PACKAGE','PACKAGE BODY'  )
and status = 'INVALID'
and owner in ('ESQUEMA1', 'ESQUEMA2', 'ESQUEMA3', etc, etc.....)
ORDER BY object_type
) loop
begin
execute immediate c1.sqltext;
dbms_output.put_line('COMPILADO '||c1.owner||'.'||c1.object_name);
exception
when others then
dbms_output.put_line('--- ERROR DE COMPILACION VERIFICAR EN : '||
                                      C1.object_type|| '  ESQUEMA '||C1.owner||'.'||
                                      c1.object_name);
end;
end loop;
end;

3 comentarios:

  1. Muy útil cuando se hace desarrollo colaborativo, funcionó también para 10g. Si no se tiene acceso a dba_objects, pueden intentarlo con all_objects.

    ResponderBorrar
  2. Muchas gracias francisco, me agrada saber que te fue de utilidad

    ResponderBorrar
  3. Muchas gracias francisco, me agrada saber que te fue de utilidad

    ResponderBorrar