Salut,
le candidat va repondre à plusieur question de type qcm, chaque reponse sera enregister dans la table niveau
je veux crée un trigger qui comparer pour chaque ligne inseré les 2 colonne REPONSE_CANDIDAT et REPONSE_CORRECT de la table NIVEAU
si les 2 colonne est égale, va enregistre le nombre de question correcte et le candidat qui repondre à ces question et le statut
le fonction qui je crée retourn 1 si les 2 colonne égale
le probleme que je ne sais pas où le problème, car le trigger ne fonctionne pas :/
table candidat
table niveau
table question_choisir
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 CREATE OR REPLACE TRIGGER tmp_niveau_ai AFTER INSERT ON NIVEAU FOR EACH ROW declare l_nbr number; l_exist number; BEGIN --retourne nombre de question de test qui passer par le candidat courant select count(*) into l_nbr from NIVEAU n,CANDIDAT c, QUESTION_CHOISIT qc where n.FK_CANDIDAT=c.ID_CANDIDAT and c.FK_TEST=qc.FK_TEST and n.FK_CANDIDAT = :new.FK_CANDIDAT; --nombre nombre de candidat existe dans tableau resultat (normalement retourn 0 ou 1) select count(*) into l_exist from RESULTAT t where t.FK_CANDIDAT = :new.FK_CANDIDAT; if l_exist = 0 then --si le candidat n'existe pas insert into RESULTAT (ID_RESULTAT , NBR_REPONSE_CORRECTE ,STATUT , FK_CANDIDAT) values (:new.FK_CANDIDAT,NULL,NULL,:new.FK_CANDIDAT); else -- si le candidat existe update RESULTAT t set t.NBR_REPONSE_CORRECTE = t.NBR_REPONSE_CORRECTE + get_nbr_question(:new.FK_CANDIDAT , :new.FK_QUESTION_CHOISIT), -- metre à jour nombre reponse correcte t.STATUT = case when (t.NBR_REPONSE_CORRECTE > l_nbr) then 'accept' else 'refusé' end --metre à jour le statut where t.FK_CANDIDAT = FK_CANDIDAT; END IF; END;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 CREATE OR REPLACE FUNCTION get_nbr_question (idC NUMBER, idQC NUMBER) RETURN NUMBER IS nbr NUMBER := 0; rcr VARCHAR2(255); rc VARCHAR2(255); BEGIN select REPONSE_CANDIDAT into rc from NIVEAU n where n.FK_CANDIDAT = idC and n.FK_QUESTION_CHOISIT = idQC; select REPONSE_CORRECT into rcr from NIVEAU n where n.FK_CANDIDAT = idC and n.FK_QUESTION_CHOISIT = idQC; IF rc = rcr THEN -- si REPONSE_CANDIDAT egale REPONSE_CORRECT, nbr =1 si non egale 0 nbr:=1; END IF; RETURN nbr; END;
Partager