Dopo aver scritto il mio trigger e compilato correttamente, durante l'uso veniva generato un errore :
ORA-04098: trigger name is invalid and failed re-validation.
Poichè il trigger era compilato correttamente sono dovuto ricorrere al comando "show errors trigger trigger_name;" per avere ulteriori chiarimenti sull'errore.
Una volta risolto il primo problema questo era il corpo del trigger :
update TESDOCUM SET CIG=(select MAX(REGISTRIVA)
from CAUSCONT
where CAUSCONTAB=CODICE
and NUMERO=:new.NUMERO)
where NUMERO=:new.NUMERO
Eseguendo il trigger sono incorso nell'errore
ORA-04091: table AM is mutating, trigger/function may not see it
Era un problema concettuale. Non si può cambiare utilizzare o modificare un record del database mentre lo stesso record è oggetto di trigger.
I database danno accesso ai dati in lettura/scrittura con degli alias.
Alla fine il trigger è il seguente:
create or replace trigger tesdocum_trg1
before insert or update
on TESDOCUM
REFERENCING new AS new
before insert or update
on TESDOCUM
REFERENCING new AS new
FOR EACH ROW
WHEN (NEW.CAUSCONTAB IS NOT NULL)
begin
WHEN (NEW.CAUSCONTAB IS NOT NULL)
begin
select MAX(REGISTRIVA) into :new.CIG
from CAUSCONT
where :new.CAUSCONTAB=CODICE;
end tesdocum_trg1;
Nessun commento:
Posta un commento