You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

289 lines
6.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

\documentclass[a4paper,11pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage[a4paper,hmargin=20mm,vmargin=30mm]{geometry}%\usepackage{fullpage}
\usepackage{url}
\usepackage{comment}
\usepackage{fancyhdr}% fancy header
\usepackage{adjustbox}
\usepackage{slashbox}
%\usepackage{times}
\usepackage{fancyvrb}
\fancypagestyle{monstyle}{
%\fancyhead{}
\renewcommand{\headrulewidth}{1pt}
%% %\renewcommand{\footrulewidth}{0.4pt}
% \fancyhead[LE]{\slshape \thepage/ \pageref{LastPage}}
%% \fancyhead[RO]{\slshape \thepage/ \pageref{LastPage}}
%\fancyhf{}
%\fancyhead[LE]{\slshape LE}
%\fancyhead[CE]{\slshape CE}
%\fancyhead[RE]{\slshape RE}
\fancyhead[LO]{\bfseries 2018-2019 BD PLS/SQL\rightmark}
%\fancyhead[CO]{\slshape APF}
\fancyhead[RO]{\bfseries ~\leftmark }
%% %\fancyfoot{}
% \fancyfoot[LE,RO]{}
\fancyfoot[CO,CE]{}%\slshape\thepage/\pageref{LastPage}}
%% %\fancyfoot[LO,RE]{\small\slshape \ddmmyyyydate version du \today}
}
% \pagestyle{fancy}
\usepackage{amsmath}
\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem{exercice}{Exercice}
\pagestyle{monstyle}
\usepackage{amsmath}
\usepackage{amsthm}
\newcommand{\code}[1]{\texttt{#1}}
\usepackage{boxedminipage}
\usepackage{setspace}
\newsavebox\svbx
\newif\ifcache
\long\def\cache#1{\ \newline
\setbox\svbx=\vbox{\leavevmode \newline \begin{spacing}{1}#1\end{spacing}}
\smallskip\par\noindent
\begin{boxedminipage}{\linewidth}
\ifcache
\leavevmode\hrule height 0pt\vskip \ht\svbx\hrule height 0pt
\else \unvbox\svbx
\fi
\end{boxedminipage}
\par\smallskip}
%\cachefalse % version prof
\cachetrue % version etudiant
\begin{document}
\begin{center}
NOM : \hfill Partiel \hfill~\\
PRENOM : \hfill 90 minutes, 75 points \hfill ~\\
GROUPE : \hfill Aucun document autoris\'e \hfill~\\
\end{center}
\begin{exercice}D\'efinitions (15 points)
\begin{enumerate}
\item (3 points) Expliquer ce qu'est une exception.
\cache{Une exception permet de r\'ealiser un traitement lors
qu'une erreur SQL se produit.}
\item (4 points) Donner un exemple d'utilisation de l'exception
\verb+NO_DATA_FOUND+.
\newsavebox\avecalter
\begin{lrbox}{\avecalter}
\begin{minipage}{\textwidth}
\begin{verbatim}
Declare
begin
Select nom into dnom FROM ELEVE Where age < 0;
EXCEPTION
when no_data_found then
INSERT INTO tligne VALUES(TO_CHAR(SQLCODE)||' '||SQLERRM||'Age negatif') ;
End;
.
/
\end{verbatim}
\end{minipage}
\end{lrbox}
\cache{\usebox\avecalter}
\item (2+2+4=8 points) Donner un exemple simple qui nest pas possible de
traiter sans un curseur, expliquer pourquoi et montrer comment
créer un curseur et comment l'utiliser dans ce cas là.
\begin{SaveVerbatim}{VerbEnv}
Declare
dnom Etudaint.nom%TYPE ;
Cursor r is Select nom from Etudiant FOR UPDATE;
BEGIN
OPEN r ;
FETCH r INTO dnom ;
WHILE r%FOUND
LOOP
UPDATE Etudiant SET nom=dnom||'old' WHERE CURRENT of r ;
FETCH r INTO dnom ;
END LOOP ;
COMMIT;
CLOSE R ;
END ;
\end{SaveVerbatim}
\cache{\code{Select nom into dnom from Etudiant ;}
ici la liste des noms ne va pas pouvoir rentrer dans dnom.
Il faut donc utiliser un cureur :
\BUseVerbatim{VerbEnv}
} \end{enumerate}
\end{exercice}
\newpage
\begin{exercice}[Soldes] (20 points)
Afin de préparer les soldes dhiver, écrivez un fichier de commandes
SQL qui, pour un produit saisi par lutilisateur, si le stock est plus
grand que 100 alors le prix est diminué de 10\% et si le stock plus
grand que 200 alors le prix est diminué de 20\%. Enfin si le stock est
vide alors ajouter dans la table \code{Tligne} une phrase pour
indiquer quil faut recommander ce produit en donnant son numéro de
produit.
\end{exercice}
\begin{SaveVerbatim}{VerbSolde}
DROP TABLE tligne ;
CREATE TABLE tligne (ligne varchar2(100)) ;
set echo off ; set verify off ; set feed off;
variable vnoproduit char(4)
prompt Entrer la reference du fournisseur :
accept vnoproduit
DECLARE
dstock number;
BEGIN
SELECT count(stock) INTO dstock
FROM Tproduit
Where noproduit=&vnoproduit;
If dstock = 0 then
INSERT INTO tligne VLAUES (Stock Null pour ce produit
||&vnoporduit||Recommander ) ;
End if;
If dstock >200 then
UPDATE Tproduit SET prixv=dprix*1.2 WHERE noproduit=&vnoproduit;
Else If dstock > 100 then
UPDATE Tproduit SET prixv=dprix*1.1 WHERE noproduit=&vnoproduit;
End if;
End;
.
/
SELECT * FROM tligne ;
set verify on ; set feed on ; set echo on ;
\end{SaveVerbatim}
\cache{%\begin{small}
\BUseVerbatim{VerbSolde}
% \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}
DROP TABLE tligne ;
CREATE TABLE tligne (ligne varchar2(100)) ;
set echo off ; set verify off ; set feed off ;
variable vreffourn char(4)
prompt Entrer la reference du produit :
accept vnoproduit
DECLARE
dnomfour char(20) ;
dreffour char(4)
BEGIN
SELECT refourn INTO dreffour FROM Tproduitfourn
WHERE nopoduit ='&vnoproduit' ;
SELECT Nom INTO dnomfour FROM TFounisseur
Where ref-fourn='dreffour;
INSERT INTO tligne VALUES (dnomfour) ;
EXCEPTION
when no_data_found then
INSERT INTO tligne VALUES(TO_CHAR(SQLCODE)||' '||SQLERRM||' Le produit
n''a pas de fournisseur' ) ;
when too_many_rows then
INSERT INTO tligne VALUES(O_CHAR(SQLCODE)||' '||SQLERRM||' Le produit a
plusieurs fournieeurs) ;
End ;
.
/
SELECT * FROM tligne ;
set verify on ; set feed on ; set echo on ;
\end{SaveVerbatim}
\cache{%\begin{small}
\BUseVerbatim{Verbfour}
% \end{small}
}
\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
dprix Tproduit.prix%TYPE ;
CURSOR r IS SELECT prixv FROM Tproduit WHERE Tproduit.stock >500
FOR UPDATE ;
BEGIN
OPEN r ;
FETCH r INTO dprix ;
WHILE r%FOUND
LOOP
UPDATE Tproduit SET prixv=dprix*1.1 WHERE CURRENT of r ;
FETCH r INTO dprix ;
END LOOP ;
COMMIT ;
CLOSE R ;
END ;
.
/
set verify on ; set feed on ; set echo on ;
\end{SaveVerbatim}
\cache{%\begin{small}
\BUseVerbatim{Verbcinq}
% \end{small}
}
%\newpage
\section*{Rappel}
\begin{center}
\includegraphics[width=14cm]{../COURS/BD.png}
\end{center}
\end{document}