From dfbba7b11b542b5846155039e2faefb58db88e85 Mon Sep 17 00:00:00 2001 From: pascal Date: Mon, 15 Feb 2021 14:02:08 +0100 Subject: [PATCH] exo9 --- COURS/C-exo9.sql | 29 +++++++++++++++++++++++++++ COURS/PLSQL.tex | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 COURS/C-exo9.sql diff --git a/COURS/C-exo9.sql b/COURS/C-exo9.sql new file mode 100644 index 0000000..45c7e9e --- /dev/null +++ b/COURS/C-exo9.sql @@ -0,0 +1,29 @@ +SET echo OFF +SET verify OFF +SET feed OFF + +DROP TABLE tligne; +CREATE TABLE Tligne(ligne VARCHAR2(200)); + +DECLARE +DnoProduit tProduit.noProduit%TYPE; +Ddesignation tProduit.designation%TYPE; +Dstock tProduit.stock%TYPE; +Dclassement NUMBER; +CURSOR r IS SELECT noProduit,designation,stock FROM tProduit ORDER BY stock; + +BEGIN +Dclassement := 1; +INSERT INTO Tligne VALUES('noProduit designation stock classement'); +OPEN r; +FETCH r INTO DnoProduit,Ddesignation,Dstock; +WHILE r%FOUND +LOOP + INSERT INTO Tligne VALUES(DnoProduit||' '||Ddesignation||' '||Dstock||' '||Dclassement); + Dclassement := Dclassement + 1; + FETCH r INTO DnoProduit,Ddesignation,Dstock; +END LOOP; +CLOSE r; +END; +. +/ diff --git a/COURS/PLSQL.tex b/COURS/PLSQL.tex index aedea63..c0b4903 100644 --- a/COURS/PLSQL.tex +++ b/COURS/PLSQL.tex @@ -1411,9 +1411,60 @@ SELECT * FROM tLigne; \begin{exercice} Afficher les produits classés par valeur du stock : No de produit, désignation, valeur du stock, classement. \end{exercice} +\cache{SET echo OFF +SET verify OFF +SET feed OFF + +DROP TABLE tligne; + +CREATE TABLE Tligne(ligne VARCHAR2(200)); + +DECLARE + +DnoProduit tProduit.noProduit\%TYPE; + +Ddesignation tProduit.designation\%TYPE; + +Dstock tProduit.stock\%TYPE; + +Dclassement NUMBER; + +CURSOR r IS SELECT noProduit,designation,stock FROM tProduit ORDER BY stock; + +BEGIN + +Dclassement := 1; + +INSERT INTO Tligne VALUES('noProduit designation stock classement'); + +OPEN r; + +FETCH r INTO DnoProduit,Ddesignation,Dstock; + +WHILE r\%FOUND + +LOOP + INSERT INTO Tligne VALUES(DnoProduit||' '||Ddesignation||' '||Dstock||' '||Dclassement); + + Dclassement := Dclassement + 1; + + FETCH r INTO DnoProduit,Ddesignation,Dstock; + +END LOOP; + +CLOSE r; + +END; + +. + +/ +} + \begin{exercice} Afficher les produits qui n’ont pas de fournisseur et les produits qui en ont avec les noms de leurs fournisseurs. \end{exercice} +\cache{TODO} \subsection{\code{UPDATE, DELETE ... WHERE CURRENT OF curseur}} Lors du parcours d'une table (ou une vue modifiable) par \code{FETCH}