Par un trigger avant update sur une table fille, je teste l'exception -02291
ORA-02291: violation de contrainte (OR.FK_ACQUIS_INTERVENTION) d'intégrité - touche parent introuvable
avec l'objectif de mettre à jour la clef de ma table principale si celle-ci n'est pas déjà présente.
Hors, il semblerait que :
- soit je gère mal mon exsception,
- soit les contrôles d'intégrités soient préalables aux triggers, de ce fait, je ne peux pas tester et intégrer la valeur de ma clef etrangere de ma table fille comme clef de ma table principale.
Quelqu'un peut il m'aidait ???
Ci joint le code du trigger
CREATE OR REPLACE TRIGGER "OR"."VERIF_ACQUIS" BEFORE
INSERT ON "ACQUIS" FOR EACH ROW declare
message_erreur varchar2(120);
CLEF_NUM_INTER_ABSENTE Exception; /* Declaration de l'exeption utilisateur
ORA-02291: violation de contrainte (OR.FK_ACQUIS_INTERVENTION) d'intégrité
touche parent introuvable */
PRAGMA exception_init( CLEF_NUM_INTER_ABSENTE,-02291);
Begin
dbms_output.put_line('entree dans trigger');
/* Si la valeur majuscule de ACQ_ACQUIS ( convertit en ??? si null ) est différente de ?O? et ?N? reçoit ?:2? */
If upper(nvl(:new.ACQ_ACQUIS,'?'))<>'O' and upper(nvl(:new.ACQ_ACQUIS,'?'))<> 'N' then
:new.ACQ_ACQUIS :='?';
insert into TRACE_ERREUR_IMPORT
(TRC_ERR_IMP_GH,TRC_ERR_IMP_TABLE,TRC_ERR_IMP_CHAMP,TRC_ERR_IMP_ACTION,TRC_ERR_IMP_CORRECTION)
values(sysdate,'ACQUIS','ACQ_ACQUIS','AJOUT','?');
End if;
/* La valeur de ACQ_CENTRE reçoit ?:1:2:3? si null*/
If :new.ACQ_CENTRE= null then
:new.ACQ_centre :='???';
insert into TRACE_ERREUR_IMPORT
(TRC_ERR_IMP_GH,TRC_ERR_IMP_TABLE,TRC_ERR_IMP_CHAMP,TRC_ERR_IMP_ACTION,TRC_ERR_IMP_CORRECTION)
values(sysdate,'ACQUIS','ACQ_CENTRE','AJOUT','???');
End if;
/* La valeur de ACQ_NUM_RENFORT reçoit 999 si null*/
If :new.ACQ_NUM_RENFORT = null then
:new.ACQ_NUM_RENFORT :=999;
insert into TRACE_ERREUR_IMPORT
(TRC_ERR_IMP_GH,TRC_ERR_IMP_TABLE,TRC_ERR_IMP_CHAMP,TRC_ERR_IMP_ACTION,TRC_ERR_IMP_CORRECTION)
values(sysdate,'ACQUIS','ACQ_NUM_RENFORT','AJOUT','999');
End if;
/* La valeur de INTER_NUMERO = null annule l?insertion*/
If nvl(:new.INTER_NUMERO,'?') = '?' then
insert into TRACE_ERREUR_IMPORT
(TRC_ERR_IMP_GH,TRC_ERR_IMP_TABLE,TRC_ERR_IMP_CHAMP,TRC_ERR_IMP_ACTION,TRC_ERR_IMP_CORRECTION)
values(sysdate,'ACQUIS','INTER_NUMERO','AJOUT','NULL = annulation');
raise_application_error(-20002,'Numéro d?intervention NULL');
End if;
EXCEPTION
/* Quand doublons de clef */
When DUP_VAL_ON_INDEX then
insert into TRACE_ERREUR_IMPORT values(sysdate,'ACQUIS','PK','AJOUT','doublons');
When CLEF_NUM_INTER_ABSENTE then
insert into INTERVENTION (INTER_NUMERO) values (:new.inter_numero);
insert into TRACE_ERREUR_IMPORT
(TRC_ERR_IMP_GH,TRC_ERR_IMP_TABLE,TRC_ERR_IMP_CHAMP,TRC_ERR_IMP_ACTION,TRC_ERR_IMP_CORRECTION)
values(sysdate,'ACQUIS','Clef_intervention','AJOUT','Creation ' || :new.inter_numero || ' dans la table INTERVENTION');
insert into acquis values(:new.ACQ_ACQUIS,:new.ACQ_CENTRE,:new.ACQ_NUM_RENFORT,:new.INTER_NUMERO);
when OTHERS then
dbms_output.put_line(' entree exception');
message_erreur:=(' ORA ' || sqlcode || ' : ' || sqlerrm);
insert into TRACE_ERREUR_IMPORT
(TRC_ERR_IMP_GH,TRC_ERR_IMP_TABLE,TRC_ERR_IMP_CHAMP,TRC_ERR_IMP_ACTION,TRC_ERR_IMP_CORRECTION)
values(sysdate,'ACQUIS','ERREUR','AJOUT',message_erreur);
End;