master
Pascal Lafourcade 5 years ago
parent bb9c13880e
commit 1e6c75f383

@ -11,6 +11,13 @@
\usepackage{slashbox} \usepackage{slashbox}
%\usepackage{times} %\usepackage{times}
\usepackage{tikz,pgflibraryarrows,pgffor,pgflibrarysnakes}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{color, colortbl}
\definecolor{Gray}{gray}{0.9}
\usepackage{fancyvrb} \usepackage{fancyvrb}
\fancypagestyle{monstyle}{ \fancypagestyle{monstyle}{
@ -27,7 +34,7 @@
%\fancyhead[CE]{\slshape CE} %\fancyhead[CE]{\slshape CE}
%\fancyhead[RE]{\slshape RE} %\fancyhead[RE]{\slshape RE}
\fancyhead[LO]{\bfseries 2018-2019 BD PLS/SQL\rightmark} \fancyhead[LO]{\bfseries 2019-2020 BD PLS/SQL\rightmark}
%\fancyhead[CO]{\slshape APF} %\fancyhead[CO]{\slshape APF}
\fancyhead[RO]{\bfseries ~\leftmark } \fancyhead[RO]{\bfseries ~\leftmark }
@ -188,138 +195,373 @@ End;
\newpage \newpage
\begin{exercice}[Soldes] (20 points) \section*{PL/SQL : NBA Statistiques}
Afin de préparer les soldes dhiver, écrivez un fichier de commandes Ci-dessous un mod\`ele de la base de donn\'ees de statistiques de la
SQL qui, pour un produit saisi par lutilisateur, si le stock est plus NBA (National Basketball Association), o\`u PG, SG, SF, PF et C sont
grand que 100 alors le prix est diminué de 10\% et si le stock plus les diff\'erents postes occup\'es par les joueurs sur le terrain. Un
grand que 200 alors le prix est diminué de 20\%. Enfin si le stock est joueur ne peut pas \^etre en activit\'e dans deux \'equipes en m\^eme temps.
vide alors ajouter dans la table \code{Tligne} une phrase pour
indiquer quil faut recommander ce produit en donnant son numéro de \begin{center}
produit. \begin{tikzpicture}[every node/.style={inner sep=0,outer sep=0}]
\end{exercice}
\node (i) at (6,0) {\begin{varwidth}{1.5in}
\begin{tabular}{|l|}
\hline
\rowcolor{Gray}CONTRAT\\
\hline
\underline{id\_contrat}\\
\#id\_joueur\\
\#id\_equipe\\
Date\_debut\\
Date\_fin\\
Salaire\_jour\\ \hline
\end{tabular}
\end{varwidth}
};
\node (a) at (0,0) {\begin{varwidth}{2.5in}
\begin{tabular}{|l|}
\hline
\rowcolor{Gray}JOUEUR\\
\hline
\underline{id\_joueur}\\
Nom\\
Pénom\\
Date\_de\_naissance\\
Taille\\
Poste('PG','SG','SF','PF','C')\\
\hline
\end{tabular}
\end{varwidth}
};
\node (f) at (8,-5) {\begin{varwidth}{2.5in}
\begin{tabular}{|l|}
\hline
\rowcolor{Gray}Match\\
\hline
\underline{id\_match}\\
Date\_match\\
\#id\_equipe\_domicile\\
\#id\_equipe\_exterieur\\
Ville\\
Categorie(Amical,Saison,Playoff,Allstar)\\
Score\_domicile\\
Score\_exterieur\\
Prolongation\\
\hline
\end{tabular}
\end{varwidth}
};
\node[draw,rectangle] (g) at (0,-5) {\begin{varwidth}{2in}
\begin{tabular}{l}
\rowcolor{Gray}JOUE\\
\hline
\underline{\#id\_joueur}\\
\underline{\#id\_match}\\
Points\\
Rebonds\\
Interceptions\\
Contres\\
Passes\\
Balles\_perdues\\
Fautes\\
\end{tabular}
\end{varwidth}};
\node[draw,rectangle] (c) at (11,0) {
\begin{tabular}{|l|}
\hline
\rowcolor{Gray}EQUIPE\\
\hline
\underline{id\_equipe}\\
Nom\\
Ville\\
Conference('Est','Ouest')\\
Date\_creation\\
\hline
\end{tabular}
};
\draw[-latex] (i) -- (a);
\draw[-latex] (i) -- (c);
\draw[-latex] (10,-2.6) -- (10.65,-1.5);
\draw[latex-] (c) -- (f);
\draw[latex-] (f) -- (g);
\draw[latex-] (a) -- (g);
\end{tikzpicture}
\end{center}
\newpage
\begin{exercice}[NBA, PLSQL] (45 points)
Le MLD ci-dessus stocke les donn\'ees des matchs NBA.
\begin{SaveVerbatim}{VerbSolde} \begin{enumerate}
\item (15 points) \'Ecrire un code PL/SQL qui permet de saisir un
nouveau joueur en entrant les six champs n\'ecessaires. Lever une
exception la clef primaire saisie n'est pas valide.
\begin{SaveVerbatim}{saisie}
DROP TABLE tligne ; DROP TABLE tligne ;
CREATE TABLE tligne (ligne varchar2(100)) ; CREATE TABLE tligne (ligne varchar2(100)) ;
set echo off ; set verify off ; set feed off;
variable vnoproduit char(4) set echo off; set verify off; set feedback off;
prompt Entrer la reference du fournisseur :
accept vnoproduit variable vidjoueur char(4)
prompt Entrer l idjoueur
accept vidjoueur
variable vnom varchar2(200)
prompt Entrer le nom du joueur
accept vnom
variable vprenom varchar2(200)
prompt Entrer le prenom du joueur
accept vprenom
variable vdate date
prompt Entrer sa date de naissance
accept vdate
variable vtaille NUMBER
prompt Entrer sa taille
accept vtaille
variable vposte char(2)
prompt Entrer l'idjoueur
accept vposte
DECLARE DECLARE
dstock number; dnbid;
EXISTEDEJAJ EXCEPTION;
didjoueur char(4);
BEGIN BEGIN
SELECT count(stock) INTO dstock SELECT count(*) INTO dnBid FROM JOUEUR WHERE id_joueur ='&vidjoueur';
FROM Tproduit IF dnbid > 0 THEN RAISE EXCEPTION
Where noproduit=&vnoproduit; END IF;
If dstock = 0 then INSERT INTO tligne VALUES ('&vidjoueur','&vnom','&prenom',to_date('&vdate',DD/MM/YYYY),'&vtaille','&vposte');
INSERT INTO tligne VLAUES (Stock Null pour ce produit
||&vnoporduit||Recommander ) ; EXCEPTION
End if; WHEN EXISTEDEJA THEN
If dstock >200 then NSERT INTO tligne VALUES ('ID joueur existe');
UPDATE Tproduit SET prixv=dprix*1.2 WHERE noproduit=&vnoproduit; END;
Else If dstock > 100 then ./
UPDATE Tproduit SET prixv=dprix*1.1 WHERE noproduit=&vnoproduit; set echo on; set verify on; set feedback on;
End if;
End;
.
/
SELECT * FROM tligne ;
set verify on ; set feed on ; set echo on ;
\end{SaveVerbatim} \end{SaveVerbatim}
\cache{%\begin{small}
\BUseVerbatim{VerbSolde}
% \end{small} \cache{\begin{small}
\BUseVerbatim{saisie}
\end{small}
} }
\newpage
\begin{exercice}[Fournisseur] (20 points)
Ecrire un fichier de commandes SQL qui demande un numéro de produit et
qui retourne le message le produit na pas de fournisseur ou le
produit a plusieurs fournisseurs, ou le 'Nom' du fournisseur sil
nen a quun. Le résultat sera placé dans une table \code{Tligne
(LIGNE varchar2(200))} et contiendra le message et le code derreur
produit par Oracle.
\end{exercice}
\begin{SaveVerbatim}{Verbfour} \newpage
\item (15 points) \'Ecrire un code PL/SQL qui, pour un
\code{id\_joueur} saisi par l'utilisateur, liste dans une table
\code{TLIGNES} son maximum de points inscript lors d'un match. La
solution propos\'ee doit mettre en place {\bf deux} m\'ecanismes un
{\bf avec} et un {\bf sans} \code{EXCEPTION} pour traiter les cas
d'erreurs suivants :
\begin{itemize}
\item \code{'joueur inconnu'}, il n'y a pas le joueur dans la table \code{JOUEUR},
\item \code{'joueur n a pas fait de match'}, il n'apparait pas
dans la table \code{JOUE}.
\end{itemize}
\begin{SaveVerbatim}{Maxpoints}
DROP TABLE tligne ; DROP TABLE tligne ;
CREATE TABLE tligne (ligne varchar2(100)) ; CREATE TABLE tligne (ligne varchar2(100)) ;
set echo off ; set verify off ; set feed off ; set echo off; set verify off; set feedback off;
variable vreffourn char(4) variable vidjoueur char(4)
prompt Entrer la reference du produit : prompt Entrer la reference du joueur :
accept vnoproduit accept vidjoueur
DECLARE DECLARE
dnomfour char(20) ; dmaxpoint number;
dreffour char(4) dnbjoueur number;
didjoueur char(4);
BEGIN BEGIN
SELECT refourn INTO dreffour FROM Tproduitfourn SELECT count(Nom) INTO dnbjoueur FROM JOUEUR WHERE id_joueur ='&vidjoueur';
WHERE nopoduit ='&vnoproduit' ;
SELECT Nom INTO dnomfour FROM TFounisseur if dnbjoueur != 0 then
Where ref-fourn='dreffour;
INSERT INTO tligne VALUES (dnomfour) ; SELECT max(points) INTO dmaxpoint FROM JOUE
WHERE id_joueur ='&vidjoueur';
INSERT INTO tligne VALUES ('Max points de'||'&vidjoueur'||' : '||to_char(dmaxpoint));
ELSE
INSERT INTO tligne VALUES('count detecte numero du joueur pas bon');
SELECT id_joueur INTO didjoueur FROM JOUEUR
WHERE id_joueur ='&vidjoueur';
end if;
EXCEPTION EXCEPTION
when no_data_found then when no_data_found then
INSERT INTO tligne VALUES(TO_CHAR(SQLCODE)||' '||SQLERRM||' Le produit INSERT INTO tligne VALUES('exception numero du joueur pas bon');
n''a pas de fournisseur' ) ; end ;
when too_many_rows then
INSERT INTO tligne VALUES(O_CHAR(SQLCODE)||' '||SQLERRM||' Le produit a
plusieurs fournieeurs) ;
End ;
. .
/ /
SELECT * FROM tligne ; SELECT * FROM tligne ;
set verify on ; set feed on ; set echo on ; set verify on; set feedback on; set echo on;
\end{SaveVerbatim} \end{SaveVerbatim}
\cache{%\begin{small} \cache{\begin{small}
\BUseVerbatim{Verbfour} \BUseVerbatim{Maxpoints}
% \end{small} \end{small}
} }
\newpage \newpage
\begin{exercice}[Curseur] (20 points)
Ecrivez un fichier de commandes SQL qui diminue de 10\% les prix des
produits qui ont un stock de plus de 500.
\end{exercice}
\begin{SaveVerbatim}{Verbcinq}
set echo off ; set verify off ; set feed off ;
Declare \item (15 points) \'Ecrire un code PL/SQL qui liste dans une table
dprix Tproduit.prix%TYPE ; \code{TLIGNES} les joueurs en activit\'e (ayant une date de fin de
contrat non nulle) du plus vieux au plus jeune.
CURSOR r IS SELECT prixv FROM Tproduit WHERE Tproduit.stock >500 \begin{center}
FOR UPDATE ; \begin{verbatim}
Nom Prenom Date de naissance Nom Equipe Actuelle
XXXXXX XXXXXXX XX/XX/XXXX XXXXXXXX
XXXXXX XXXXXXX XX/XX/XXXX XXXXXXXX
XXXXXX XXXXXXX XX/XX/XXXX XXXXXXXX
...
\end{verbatim}
\end{center}
\begin{SaveVerbatim}{Joueur}
DROP TABLE tligne ;
CREATE TABLE tligne (ligne varchar2(100)) ;
set echo off;
set verify off;
set feedback off;
DECLARE
dnom varchar2(20);
dprenom varchar2(20);
ddate date;
dnomequipe varchar2(20);
CURSOR c IS SELECT j.Nom, j.Prenom, j.Date_de_naissance, e.Nom FROM JOUEUR j, APPARTIENT a, EQUIPE e
WHERE a.id_joueur = j.id_joueur and e.id_equipe = a.id_equipe and a.Date_fin is NULL
Order by Date_de_naissance;
BEGIN BEGIN
OPEN r ; OPEN c;
FETCH r INTO dprix ;
WHILE r%FOUND INSERT INTO tligne VALUES ('Nom Prenom Date de naissance Nom Equipe Actuelle');
FETCH c INTO dnom, dprenom, ddate, dnomequipe;
WHILE c%found
LOOP LOOP
UPDATE Tproduit SET prixv=dprix*1.1 WHERE CURRENT of r ; INSERT INTO tligne VALUES (dnom||' '||dprenom||' '||to_char(ddate)||' '||dnomequipe);
FETCH r INTO dprix ; FETCH c INTO dnom, dprenom, ddate, dnomequipe;
END LOOP ; END LOOP;
COMMIT ;
CLOSE R ; CLOSE C;
END ; END;
. .
/ /
set verify on ; set feed on ; set echo on ;
SELECT * FROM tligne ;
set verify on;
set feedback on;
set echo on;
\end{SaveVerbatim} \end{SaveVerbatim}
\cache{%\begin{small}
\BUseVerbatim{Verbcinq} \cache{%\begin{small}
% \end{small} \BUseVerbatim{Joueur}
} %\end{small}
}
%% \item (20 points) Lister dans une table \code{TLIGNES} tous les
%% joueurs ayant particip\'e \`a un ALLSTAR de la conf\'erence Est et
%% ceux de la conf\'erence Ouest avec les informations suivantes :
%% \begin{center}
%% \begin{small}
%% \begin{verbatim}
%% ALLSTAR MATCH
%% EQUIPE de l'EST
%% Nom Prenom Poste Equipe Actuelle
%% XXXXXX XXXXXXX XXXXXX XXXXXXXX
%% XXXXXX XXXXXXX XXXXXX XXXXXXXX
%% EQUIPE de l'EST
%% Nom Prenom Poste Equipe Actuelle
%% XXXXXX XXXXXXX XXXXXX XXXXXXXX
%% XXXXXX XXXXXXX XXXXXX XXXXXXXX
%% \end{verbatim}
%% \end{small}
%% \end{center}
%% \begin{SaveVerbatim}{Allstar}
%% DECLARE
%% dnom varchar2(20); dprenom varchar2(20);
%% dposte char(2); dnomequipe varchar2(20);
%% CURSOR Cest IS SELECT j.Nom, j.Prenom, j.Poste, e.Nom FROM JOUEUR j,
%% APPARTIENT a, EQUIPE e WHERE a.id_joueur = j.id_joueur and e.id_equipe
%% = a.id_equipe and e.conference='Est' and j.id_joueur in (SELECT
%% id_joueur FROM JOUE je, GAME g where g.Categorie='Allstar' and
%% g.id_game=je.id_game);
%% CURSOR Couest IS SELECT j.Nom, j.Prenom, j.Poste, e.Nom FROM JOUEUR j,
%% APPARTIENT a, EQUIPE e WHERE a.id_joueur = j.id_joueur and e.id_equipe
%% = a.id_equipe and e.conference='Ouest' and j.id_joueur in (SELECT
%% id_joueur FROM JOUE je, GAME g where g.Categorie='Allstar' and
%% g.id_game=je.id_game);
%% BEGIN
%% INSERT INTO tligne VALUES ('ALLSTAR GAME);
%% INSERT INTO tligne VALUES ('Conference Est');
%% INSERT INTO tligne VALUES ('Nom Prenom Poste Nom Equipe Actuelle');
%% OPEN Cest;
%% FETCH Cest INTO dnom, dprenom, dposte, dnomequipe;
%% WHILE Cest%found LOOP
%% INSERT INTO tligne VALUES (dnom||' '||dprenom||' '||dposte||' '||dnomequipe);
%% FETCH Cest INTO dnom, dprenom, dposte, dnomequipe;
%% END LOOP;
%% CLOSE Cest;
%% INSERT INTO tligne VALUES ('Conference Ouest');
%% OPEN Couest;
%% INSERT INTO tligne VALUES ('Nom Prenom Poste Nom Equipe Actuelle');
%% FETCH Couest INTO dnom, dprenom, dposte, dnomequipe;
%% WHILE Couest%found LOOP
%% INSERT INTO tligne VALUES (dnom||' '||dprenom||' '||dposte||' '||dnomequipe);
%% FETCH Couest INTO dnom, dprenom, dposte, dnomequipe;
%% END LOOP;
%% CLOSE Couest;
%% END;
%% .
%% /
%% SELECT * FROM tligne ;
%% \end{SaveVerbatim}
%% \cache{\begin{footnotesize}
%% \BUseVerbatim{Allstar}
%% \end{footnotesize}
%% }
\end{enumerate}
\end{exercice}

Loading…
Cancel
Save