0% found this document useful (0 votes)
9 views5 pages

BBD

Uploaded by

khouni Hadil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

BBD

Uploaded by

khouni Hadil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

compte address : sgbdil

mdp : mpassil

ACTIVITE 1:
creer un prog PL/SQL permettent de calculer et afficher le perimetre d'un cercle

declare
p float ;
begin
p:=2*3.14*&rayon;
dbms_output.put_line('le perimetre = ' ||p);
end ;
/

set serveroutput on
/
ACTIVITE 2:
creer un bloc anonyme permettant de calculer et affichier le nbr des lignes d'une
table donne

declare
n integer;
begin
select count(*) into n
from &nomtable;
dbms_output.put_line(n ||' ligne(s) selectionnee(s)');
end ;
/

partie B:

A/ select count(*)
2 from objet
3 where idobj not in (select idobj from enchere)
4 ;

COUNT(*)
----------
7
ACTIVITE 3:

declare
vidobj objet.idobj%type := 'OBJ00001';
vmin enchere.valeur%type;
vmax enchere.valeur%type;
begin
select min(valeur),max(valeur) into vmoin,vmax
from enchere
where idonj=vidobj;
dbms_output.put_line('la valeur mini est :'|| vmin);
dbms_output.put_line('la valeur max :'|| vmax);
end;
/

ACTIVITE 4:
creez un bloc pl/sql qui permet de calculer et afficher la moyenne des ages

set serveroutput on;


declare
ma float;
begin
select avg(to_char(sysdate,'yyyy') - to_char(datn,'yyyy')) into ma from client ;
dbms_output.put_line('moyenne =' || ma);
end;
/

ACTIVITE 5:

set serveroutput on ;
declare
cat varchar(20);
idcl client.id_client%type:='cl000001';
pd enchere.date_ench%type;
dd enchere.date_ench%type;
vexcept exception;
begin
select min(date_ench), max(date_ench) into pd,dd
from enchere
where id_acheteur=idcl;

if pd is null and dd is null then


raise vexcept ;
end if;

if Add_Months(pd,6) > sysdate then


cat:='new';
elsif Add_Months(pd,24) < sysdate And Add_Months(dd,6) > sysdate then
cat:='ancien';
else
cat:='autre';
end if;
dbms_output.put_line(cat);
exception
when vexcept then
raise_application_error(-20001,'client inexistant');
end;
/

ACTIVITE 6:

declare
nbp integer;
ob integer;
idench integer;
maxench integer;
an char(20);
begin
an:= to_char(sysdate,'yyyy')-4;
for a in an..an+3
loop

dbms_output.put_line('----------------------'|| a
||'---------------------------------');
select count(distinct id_acheteur) ,count(idobj),count(idenchere) into
nbp,ob,idench
from enchere
where to_char(date_ench,'yyyy')=a;
select max(count(idenchere)) into maxench
from enchere
where to_char(date_ench,'yyyy')=a
group by idobj;

dbms_output.put_line('le nombre de participants : '|| nbp);


dbms_output.put_line('le nombre des objets : '|| ob );
dbms_output.put_line('le nombre des encheres : '|| idench);
dbms_output.put_line('le nombre max enchere : '|| maxench);

end loop;
dbms_output.put_line('-----------------------------------------------------------')
;
end;
/

activite: curseur explicites :


set serveroutput on;
declare
cursor c is
select nom_cl
from client c,objet o
where c.id_client=o.id_vendeur
intersect
select nom_cl
from client c, enchere e
where c.id_client=e.id_acheteur;
vcord c%ROWTYPE;
begin
open c;
loop
fetch c into vcord ;
exit when c%NOTFOUND;
dbms_output.put_line(vcord.nom_cl);
end loop;
close c;
end ;
/

avec boucle for :


declare
cursor c is
select nom_cl
from client c,objet o
where c.id_client=o.id_vendeur
intersect
select nom_cl
from client c, enchere e
where c.id_client=e.id_acheteur;
vcord c%ROWTYPE;

begin
for vrecord in c
loop
dbms_output.put_line(vcord.nom_cl);
end loop;
end ;
/

ecrire un scripte pl/sql permettent de faire le meme exercice sans cursor ixplicite
:

begin
for vrec in(
select nom_cl
from client c ,objet o
where c.id_client =o.id_vendeur
intersect
select nom_cl
from client c , enchere e
where c.id_client=e.id_acheteur)
loop
dbms_output.put_line(vrec.nom_cl);
end loop;
end ;
/

exercice :
ecrire un bloc pl/sql permettant de calculer et afficher le prix moyen pondere
de chaque article retable
un article est considere reutable si son nombre d'enchere depasse 10% du nombre
total
des encheres

declare
cursor c is
select *
from produit
where idpr in (select idpr from enchere e, objet o
where e.idobj=o.idobj
group by idpr
having count(idenchere)>(select 0.1*count(*) from enchere));
pmp float;
begin
for vrec in c
loop
select sum(count(idenchere)*max(valeur))/sum(count(idenchere)) into pmp
from enchere e ,objet o
where e.idobj=e.idobj and idpr=vrec.idpr
group by o.idobj;
dbms_output.put_line(vrec.idpr || ' pmp= '||pmp);
end loop;
end ;
/

afficher la liste des clients propect


un client est dit prospect ssi il n'a pas gagne une enchere et les artivcle
convoitises
represente de la matie de articles.

declare
cursor c is
select id_client, idpr
vr c%rowtype;
begin
for vr in c
loop
dbms_output.put_line();
end loop;
end ;
/

You might also like