› Fóruns › SQL e PL/SQL › TRIGGER – POR FAVOR, ME AJUDEM! › TRIGGER – POR FAVOR, ME AJUDEM!
Tytto,
não sei se entendi direito. A trigger descrita abaixo insere os registros na tabela Rejeicoes e deleta todos os registros da tabela Movimento já existentes em Rejeicoes, quando a mesma é atualizada ou deletada. Somente é inserido na tabela Rejeicoes quando não tiver o mesmo registro contido na tabela Movimento.
OBS: Como não conheço a estrutura e o relacionamentos de suas tabelas segue apenas um exemplo.
create or replace trigger tr_Mov
before update or delete on movimento for each row
declare
PRAGMA AUTONOMOUS_TRANSACTION;
begin
merge into rejeicoes r
using movimento m on (r.nf = m.nf)
when matched then
update set r.movimento = m.movimento
,r.CAMPO = m.CAMPO
,r.CAMPO2 = m.CAMPO2
,r.CAMPO3 = m.CAMPO3
when not matched then
insert values (m.movimento, m.CAMPO, m.CAMPO2, m.CAMPO3);
commit;
delete from movimento where exists (select * from rejeicoes where r.nf = m.nf);
commit;
end tr_mov;
abraço.