Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Exercice N°1 : Exercice N°4 Exemple cursor

DECLARE DECLARE
a integer; type TTabEntier is VARRAY(50) of INTEGER; CREATE TABLE resultat ( nom varchar2(30), Qte number
b integer; tab TTabEntier; );
aux integer; Taille constant integer :=20; DECLARE
BEGIN i integer; CURSOR Client_rabat IS
a:=1; aux integer; SELECT nom, QteCom FROM client cli, commande co ,
b:=2; BEGIN ligne_commande lc WHERE
aux:=a; tab:=TTabEntier(); cli.numcli=co.numcli and co.numcom=lc.numcom and
a:=b; tab.extend(Taille); ville= 'Rabat' ;
b:=aux; for i in 1..taille loop nom client.nom%TYPE ;
DBMS_OUTPUT.PUT_Line(a||''||b); tab(i):=i*i; qte ligne_commande.QteCom%TYPE ;
END; end loop; BEGIN
Exercice N°2 for i in 1..Taille loop OPEN Client_rabat ;
DBMS_OUTPUT.PUT(tab(i)||''); FETCH Client_rabat INTO nom, qte;
DECLARE end loop; WHILE Client_rabat %found LOOP
a integer default 3; DBMS_OUTPUT.PUT_Line(''); IF qte>1 THEN
f integer; for i in 1..Trunc(taille/2) loop INSERT INTO resultat VALUES ( nom, qte) ;
i integer; aux:=tab(i); END IF ;
BEGIN tab(i):=tab(taille-i+1); FETCH Client_rabat INTO nom, qte;
f:=1; tab(taille-i+1):=aux; END LOOP;
for i in 1..a loop end loop;
f:=f*i; for i in 1..Taille loop create or REPLACE function Prix_TTC(idc NUMBER)
end loop; DBMS_OUTPUT.PUT(tab(i)||''); return NUMBER is
DBMS_OUTPUT.PUT_Line('factorielle de '||a||' = '||f); end loop; CURSOR PHT (n NUMBER) is
END; DBMS_OUTPUT.PUT_Line(''); SELECT sum(quantité*p.pu) somme from commande c,
END; produit p where c.numprod=p.numprod and numcli=n and
Exercice N°3 p.desig like '%Ordinateur%'
Exercice N°5 group by c.numcli;
DECLARE prixht PHT%ROWTYPE;
a integer default 48; DECLARE begin
b integer default 84; rec client%rowtype; open PHT(idc);
aux integer; FETCH PHT INTO prixht;
BEGIN BEGIN if PHT%NOTFOUND then
while b!=0 loop select * into rec from client where close PHT;
aux:=a; datenaiss=To_Date('12/02/1984','DD/MM/YYYY'); return 0;
a:=b; DBMS_OUTPUT.PUT_LINE(rec.nom); else
b:=MOD(aux,b); END; close PHT;
end loop; return prixht.somme*1.2;
DBMS_OUTPUT.PUT_Line('le PGCD = '||a ); end if;
END; end;

You might also like