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
|
create table s_dating_session (
id_session number primary key,
nom_session varchar2(10),
max_inscription number(2)
)
/
create table s_dating_eleve_session (
id_eleve number,
id_session number references s_dating_session,
Constraint Pk_s_dating_eleve_session Primary Key (id_session, id_eleve)
)
/
insert into s_dating_session values (1, 'TEST1', 2)
/
insert into s_dating_eleve_session values (10, 1)
/
commit
/
Create Or Replace Procedure Inscription (
id_eleve In s_dating_eleve_session.id_eleve%Type,
id_session In s_dating_eleve_session.id_session%Type
) Is
max_inscription s_dating_session.max_inscription%Type;
encour_inscrit Pls_Integer;
--
RESERVE Exception;
Pragma Exception_Init(RESERVE, -00054);
Begin
Select Nvl(sd.max_inscription,0),
Nvl((Select Count(*)
From s_dating_eleve_session des
Where des.id_session = sd.id_session
),0) encour_inscrit
Into Inscription.max_inscription,
Inscription.encour_inscrit
From s_dating_session sd
Where sd.id_session = Inscription.id_session
For Update Nowait;
--
If max_inscription < encour_inscrit + 1
Then
Raise_Application_Error(-20000,'Inscription impossible le nombre de place disponible a été épuisé.');
End If;
--
Insert Into s_dating_eleve_session
(id_eleve,
id_session
)
Values (Inscription.id_eleve,
Inscription.id_session
);
Exception
When NO_DATA_FOUND Then
Raise_Application_Error(-20000,'L''identifiant de la session est inexistant.');
When RESERVE Then
Raise_Application_Error(-20000, 'L''enregistrement est actuelement verrouilé par un autre utilisateur. Réessayer plus tard.');
End;
/ |
Partager