Bom Pessoal,
Vou compartilhar um procedimento para fazer a exclusão de triggers duplicadas que são utilizadas para entregar id´s para cada registro inserido na tabela, segue abaixo:
begin
----------------------------------------------------------
-- exclui triggers duplicadas -------
----------------------------------------------------------
for rc1 in (select tta.*
from (select t.TRIGGER_NAME,
upper(t.TRIGGER_NAME) as nome_trg_upper,
count(1) over(partition by t.TABLE_NAME order by t.TRIGGER_TYPE) as num_trg,
row_number() over(partition by t.TABLE_NAME order by t.TRIGGER_TYPE) as reg_trg,
t.TRIGGER_TYPE,
t.TRIGGERING_EVENT,
t.TABLE_OWNER,
t.base_object_type,
t.TABLE_NAME,
t.STATUS
from user_triggers t
where t.TRIGGER_TYPE = 'BEFORE EACH ROW' and t.TRIGGERING_EVENT = 'INSERT'
) tta
order by 1 desc) loop
if rc1.num_trg > 1 and rc1.reg_trg > 1 then
execute immediate 'DROP TRIGGER ' || '"' || rc1.table_owner || '"."' ||
rc1.trigger_name || '"';
end if;
end loop;
----------------------------------------------------------
-- recompila triggers -------
----------------------------------------------------------
for rc1 in (select tta.*
from (select t.TRIGGER_NAME,
upper(t.TRIGGER_NAME) as nome_trg_upper,
count(1) over(partition by t.TABLE_NAME order by t.TRIGGER_TYPE) as num_trg,
row_number() over(partition by t.TABLE_NAME order by t.TRIGGER_TYPE) as reg_trg,
t.TRIGGER_TYPE,
t.TRIGGERING_EVENT,
t.TABLE_OWNER,
t.base_object_type,
t.TABLE_NAME,
t.STATUS
from user_triggers t
where t.TRIGGER_TYPE = 'BEFORE EACH ROW' and t.TRIGGERING_EVENT = 'INSERT'
) tta
order by 1 desc) loop
if rc1.num_trg = 1 and rc1.reg_trg = 1 then
execute immediate 'ALTER TRIGGER ' || '"' || rc1.table_owner || '"."' ||
rc1.trigger_name || '" COMPILE';
end if;
end loop;
----------------------------------------------------------
end;
Essa é uma dica simples, mais pode facilitar muito a vida de um DBA que encontre esse tipo de situação.
Qualquer dúvida sobre o post estou a disposição. Fiquem na Paz.
Nenhum comentário:
Postar um comentário