Bonjour,

Je suis actuellement dans un état critique, lors de ma préparation pour mon examen final qui a lieu le 01/07/14.. J'ai eu un blocage sur une procédure..

Voila les tables :

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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
 
CREATE TABLE Region(
idRegion INTEGER NOT NULL,
nomRegion VARCHAR(50) NOT NULL,
CONSTRAINT Region_IdRegion_PK PRIMARY KEY (idRegion));
 
CREATE SEQUENCE seq_reg START WITH 1 INCREMENT BY 1;
INSERT INTO Region VALUES(seq_reg.NEXTVAL,'Grand Casablanca');
 
-----------------------------------------------
CREATE TABLE ProvincePrefecture(
IdProvPref INTEGER NOT NULL,
nomProvPref VARCHAR(50) NOT NULL,
idRegion INTEGER NOT NULL,
CONSTRAINT ProPref_IdProvPref_PK PRIMARY KEY (idProvPref),
CONSTRAINT ProPref_IdRegion_FG FOREIGN KEY (idRegion) REFERENCES Region(idRegion));
 
CREATE SEQUENCE seq_ProvPref START WITH 1 INCREMENT BY 1;
 
INSERT INTO ProvincePrefecture VALUES(seq_ProvPref.NEXTVAL, 'Prefecture de Casablanca',1);
-----------------------------------------------
CREATE TABLE TrancheAge(
idTranche INTEGER NOT NULL,
tranche VARCHAR(20) NOT NULL,
CONSTRAINT TrancheAge_idTranche_PK PRIMARY KEY (idTranche));
 
CREATE SEQUENCE seq_Tranche START WITH 1 INCREMENT BY 1;
 
INSERT INTO TrancheAge VALUES(seq_Tranche.NEXTVAL,'Entre 35 et 45 ans');
 
-----------------------------------------------
CREATE TABLE Circonscription(
idCirconscription INTEGER NOT NULL,
nomCir VARCHAR(20) NOT NULL,
NombreSiege INTEGER NOT NULL,
idProvPref INTEGER NOT NULL,
CONSTRAINT Circon_idCircon_PK PRIMARY KEY (idCirconscription),
CONSTRAINT Circon_idProvPref_FG FOREIGN KEY (idProvPref) REFERENCES ProvincePrefecture(idProvPref));
 
CREATE SEQUENCE seq_Circon START WITH 1 INCREMENT BY 1;
 
INSERT INTO Circonscription VALUES(seq_Circon.NEXTVAL,'Anfa',20,1);
 
-----------------------------------------------
CREATE TABLE Parti(
idParti INTEGER NOT NULL,
nomParti VARCHAR(20) NOT NULL,
CONSTRAINT Parti_idParti_PK PRIMARY KEY (idParti));
 
CREATE SEQUENCE seq_Parti START WITH 1 INCREMENT BY 1;
 
INSERT INTO Parti VALUES(seq_Parti.NEXTVAL,'Transport');
 
-----------------------------------------------
CREATE TABLE Candidat(
CINcandidat VARCHAR2(8) NOT NULL,
nomCandidat VARCHAR(10) NOT NULL,
prenomCandidat VARCHAR(10) NOT NULL,
DateNC DATE NOT NULL,
niveauScolaire VARCHAR(10) NOT NULL,
NumOrdreListe INTEGER NOT NULL,
adrCandidat VARCHAR2(100) NOT NULL, 
idCirconscription INTEGER NOT NULL,
idParti INTEGER NOT NULL,
idTrancheAge INTEGER NOT NULL, 
CONSTRAINT Candidat_CINCandidat_PK PRIMARY KEY (CINcandidat),
CONSTRAINT Candidat_idCirconscription_FG FOREIGN KEY (idCirconscription) REFERENCES Circonscription(idCirconscription),
CONSTRAINT Candidat_idParti_FG FOREIGN KEY (idParti) REFERENCES Parti(idParti),
CONSTRAINT Candidat_idTrancheAge_FG FOREIGN KEY (idTRancheAge) REFERENCES TrancheAge(idTranche));
 
INSERT INTO Candidat VALUES('BK389154','Lahlou','Youssef',to_date('26/06/14','dd/mm/yy'),'supérieur',1,'Cartier Anfa, BD biranZaran, rue Hafid Salafi App 6, App 1',1,1,1);
2) La question est la suivante : Créer une procédure stockée qui affiche le nombre de condidats par province pour une région donnée comme paramètre.

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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 
CREATE OR REPLACE PROCEDURE Nbr_candidat
(idReg in INTEGER) AS
-- Declaration variable typé
-- Exception :
AucunCandidat EXCEPTION;
-- Conteneur :
IdProvPref_v INTEGER;
idCirconscription_v INTEGER;
Cont_Candidat INTEGER;
-- 1er curseur qui recupere l'id de province
CURSOR C1 IS
SELECT DISTINCT IdProvPref
FROM ProvincePrefecture
WHERE idReg = idRegion;
-- 2eme curseur qui recupere id circonscription a partir du premier curseur;
CURSOR C2(C1) IS
SELECT DISTINCT idCirconscription
FROM Circonscription
WHERE idProvPref = C1;
-- 3eme curseur qui récupere le count des id candidat pour une circonscription données
 
-- Début du traitement de la question avec les curseurs
BEGIN
-- utilisation implicite de C1 (toute les lignes)
FOR idProvPref_V IN C1 LOOP
EXIT WHEN C1%NOTFOUND OR C1%NOTFOUND IS NULL;
 
-- J'utilise les valeurs récupéré par le C1 dans C2
-- Utilisation Explicite de C2
OPEN C2(idProvPref_V);
FETCH C2 INTO idCirconscription_v;
-- Condition : Si C2 boucle et ne trouve pas le champ 
IF C2%NOTFOUND THEN
DBMS_OUTPUT.PUT_LINE('Aucune idCirconscription na été trouver grace a C2');
END IF;
-- INSTRUCTION cont le nombre des candidat
SELECT COUNT(DISTINCT id_candidat) INTO Cont_Candidat
FROM Candidat
WHERE idCirconscription_v = id_Circonscription;
-- SI le cont est plus grd que 0 ecrire le resultat
IF Cont_Candidat > 0 THEN
DBMS_OUTPUT.PUT_LINE('Le nombre des candidat de la region :'||idReg||' qui as comme prefecture :'||idProvPref_V||' est : '||Cont_Candidat);
ELSE
-- SINON RAISE EXCEPTION DECLARé PLUS HAUT
RAISE AucunCandidat;
CLOSE C2;
END LOOP;
EXCEPTION
WHEN AucunCandidat THEN
DBMS_OUTPUT.PUT_LINE('Il n y a actuellement aucune candidat dans cette region.');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Erreur indeterminé');
END;
END Nbr_candidat;
/
Le message d'erreur lors de son exécution est le suivante :
Nom : Erreur Procedure NBR_candidat.png
Affichages : 227
Taille : 9,8 Ko


Merci d'avoir portée votre attention a ce message.

Toute vos proposition sont déjà et d'ors les bienvenues pour résoudre le problème.


Cordialement,
DEV_UCF