BBD
BBD
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
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;
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;
end loop;
dbms_output.put_line('-----------------------------------------------------------')
;
end;
/
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 ;
/
declare
cursor c is
select id_client, idpr
vr c%rowtype;
begin
for vr in c
loop
dbms_output.put_line();
end loop;
end ;
/