Sie sind auf Seite 1von 4

EXO 1

Declare
a integer :=1;
b integer :=2;
temp integer;

Begin
temp:=a;
a:=b;
b:=temp;
DBMS_output.put_line('a='||a||'b='||b);
end;

------------------------------------------------------------------------------
EXO 2
Declare
a integer :=10;
fact integer:=1;
begin
LOOP
fact:=fact*a;
a:=a-1;
exit when a<=1;
end loop;
DBMS_output.put_line(fact);
end;

OR USING FOR LOOP

Declare
a integer :=10;
fact integer:=1;
begin
for i in 1..a loop
fact:=fact*i;
end loop;
DBMS_output.put_line(fact);

OR USING WHILE LOOP

Declare
a integer :=10;
fact integer:=1;
begin
while(a>1) loop
fact:=fact*a;
a:=a-1;
end loop;
DBMS_output.put_line(fact);
end;
end;

------------------------------------------------------------------------------
EXO 3

Declare
a integer :=48;
b integer :=84;
r integer;
begin
while(a!=0) loop
r:=b mod a;
b:=a;
a:=r;
end loop;
DBMS_output.put_line(b);
end;

------------------------------------------------------------------------------
EXO 4

Declare
TYPE numberTab IS VARRAY (50) OF NUMBER;
tab numberTab;
temp integer;

BEGIN
tab:=numberTab();
tab.extend(20);
for i in 1..20 loop
tab(i):=i*i;
end loop;
for i in 1..10 loop
temp:=tab(i);
tab(i):=tab(20-i+1);
tab(20-i+1):=temp;
end loop;
for i in 1..20 loop
DBMS_output.put_line(tab(i));
end loop;
end;

------------------------------------------------------------------------------

EXO 5

Declare
eng client%rowtype;
begin
select * into eng from client
where DateNaiss=To_Date('1988/12/14','YYYY/MM/DD');
DBMS_output.put_line(eng.nom);
end;

OR USING CURSORS

declare
eng client%rowtype;
cursor c is
select * from client
where DateNaiss=To_Date('1988/12/14','YYYY/MM/DD');

begin
open c;
fetch c into eng;
DBMS_output.put_line(eng.nom);
close c;
end;

OR

Declare

eng client%rowtype;
cursor c (D varchar) is
select * from client
where DateNaiss=To_Date(D,'YYYY/MM/DD');

begin
open c('1988/12/14');
fetch c into eng;
DBMS_output.put_line(eng.nom);
close c;
end;
---------------------------------------------------------------

EXO 6
1)
create or replace Function Prix_TTC(ide NUMBER, TVA NUMBER) return NUMBER is
Cursor PHT (n number) is
select sum(pu*quantite) from Produit P,Commande c
where P.numprod=c.numprod and c.numcli=n and Design like '%ordinateur%'
group by numcli;
prix number;
Begin
open PHT(ide);
fetch PHT into prix;
if PHT%found then
close PHT;
return Prix*(1+TVA);
else close PHT;
return 0;
end if;
end;

2)
create or replace Procedure cli_prod is

cursor Design_prod_client (n Number) is


select distinct Design
from Commande,Produit
where commande.Numcli=n and commande.Numprod=Produit.numprod;

cursor C_Client is
select distinct client.Numcli,client.nom
from Client,commande
where client.numcli = commande.numcli;

Begin
for cl in c_client loop
DBMS_output.put_line(cl.Numcli || ' ' || cl.nom);
for d in Design_prod_client (cl.Numcli) loop
DBMS_output.put_line(', '||d.design);
end loop;
DBMS_output.new_line;
end loop;
end;