Académique Documents
Professionnel Documents
Culture Documents
*********************************************************/
/*
*/
-- QUESTION 1
-- 1.a)
/*
drop table LAB_ARTICLE cascade constraints;
drop table LAB_FOURNISSEUR cascade constraints;*/
drop table LAB_ACHETER cascade constraints;
drop table LAB_CLIENT cascade constraints;
*/
-- 1.b)
-- 1.c)
-- 1.d)
-- i)
-- ii)
-- 1.e)
-- 2)
-- 2.a)
if (MOD(V_POR, 5) = 0) then
dbms_output.put_line('Le prix du parapluie ' || V_POR
||'%'||' '|| 'est de ' ||' '|| round(V_PRIX_PARAPLUIE*(V_POR/100),
2)||'$');
end if;
end loop;
end;
-- 2.a.i)
set serveroutput on;
-- 2.a.ii)
execute LAB_SP_PRIX_PARAPLUIE;
-- 2.b)
-- 2.b.i et 2.b.ii)
create or replace procedure LAB_SP_PRIX_PARAPLUIE_TMR is V_PRIX_PARAPLUIE
number(6,2);
begin
select MNT_PRIX_INVENT_ART into V_PRIX_PARAPLUIE
from LAB_ARTICLE
where LIBELLE_ART = 'Parapluie';
for V_POR in reverse 80..100
loop
if (MOD(V_POR, 5) = 0) then
dbms_output.put_line('Le prix du parapluie ' || V_POR
||'%'||' '|| 'est de ' ||' '|| round(V_PRIX_PARAPLUIE*(V_POR/100),
2)||'$');
end if;
end loop;
exception -- 2.b.iii)
-- 2.b.iv)
insert into LAB_ARTICLE (NO_ARTICLE, LIBELLE_ART, STOCK_ART,
MNT_PRIX_INVENT_ART)
values (6, 'Parapluie', 10, 5.29);
-- 2.b.v)
execute LAB_SP_PRIX_PARAPLUIE;
-- 2.b.vi)
execute LAB_SP_PRIX_PARAPLUIE_TMR;
-- 2.c
-- 2.c.i et 2.c.ii)
create or replace procedure LAB_SP_PRIX_PARAPLUIE_TMR_NDF is
V_PRIX_PARAPLUIE number(6,2);
begin
select MNT_PRIX_INVENT_ART into V_PRIX_PARAPLUIE
from LAB_ARTICLE
where LIBELLE_ART = 'Parapluie';
for V_POR in reverse 80..100
loop
if (MOD(V_POR, 5) = 0) then
dbms_output.put_line('Le prix du parapluie ' || V_POR
||'%'||' '|| 'est de ' ||' '|| round(V_PRIX_PARAPLUIE*(V_POR/100),
2)||'$');
end if;
end loop;
exception
-- 2.c.iii)
when NO_DATA_FOUND then --(1)
dbms_output.put_line('Il n''y a aucun article avec le libelle
Parapluie'); --(2)
end;
-- 2.c.iv)
-- (1)
-- (2)
delete from LAB_ARTICLE
where LIBELLE_ART = 'Parapluie';
-- 2.c.v)
execute LAB_SP_PRIX_PARAPLUIE_TMR;
-- 2.c.vi)
execute LAB_SP_PRIX_PARAPLUIE_TMR_NDF;
/
*========================================================================
======
QUESTION 3.
=========================================================================
=====*/
-- 3.a)
create or replace procedure LAB_SP_INFO_CLIENT (P_I_NO_CLIENT in number)
is
V_ADR_CLI varchar2(30);
V_VILLE_CLI varchar2(30);
begin
select ADR_CLI, VILLE_CLI into V_ADR_CLI, V_VILLE_CLI
from LAB_CLIENT
where NO_CLIENT = P_I_NO_CLIENT;
dbms_output.put_line(V_ADR_CLI);
dbms_output.put_line(V_VILLE_CLI);
exception
when NO_DATA_FOUND then
dbms_output.put_line('Le client avec le numro '||
P_I_NO_CLIENT||' n''existe pas.');
end;
-- 3.a.i)
execute LAB_SP_INFO_CLIENT (11);
-- 3.a.ii)
execute LAB_SP_INFO_CLIENT (14);
/
*========================================================================
======
QUESTION 4.
=========================================================================
=====*/
-- 4.a)
create or replace procedure LAB_SP_FOURNISSEUR is
V_NO_FOURNISSEUR number(6);
V_NOM_FOU varchar2(30);
V_VILLE_FOU varchar2(30);
cursor CURSEUR is
select NO_FOURNISSEUR, NOM_FOU, VILLE_FOU into V_NO_FOURNISSEUR,
V_NOM_FOU, V_VILLE_FOU
from LAB_FOURNISSEUR
order by NOM_FOU asc;
begin
open CURSEUR;
loop
fetch CURSEUR into V_NO_FOURNISSEUR, V_NOM_FOU, V_VILLE_FOU;
exit when CURSEUR%NOTFOUND;
dbms_output.put_line('No : '||V_NO_FOURNISSEUR||
', Fournisseur : '||V_NOM_FOU||
', Ville : '||V_VILLE_FOU);
end loop;
close CURSEUR;
end;
-- 4.b)++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++
execute LAB_SP_FOURNISSEUR;
-- 4.c)++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++
create or replace procedure LAB_SP_FOURNISSEUR_LOOP is
cursor CURSEUR is
select NO_FOURNISSEUR, NOM_FOU, VILLE_FOU
from LAB_FOURNISSEUR
order by NOM_FOU asc;
begin
for V_DONNEES in CURSEUR
loop
dbms_output.put_line('No : '||V_DONNEES.NO_FOURNISSEUR||
', Fournisseur : '||
V_DONNEES.NOM_FOU||
', Ville : '||V_DONNEES.VILLE_FOU);
end loop;
end;
-- 4.d)++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++
execute LAB_SP_FOURNISSEUR_LOOP;
/
*========================================================================
======
QUESTION 5.
=========================================================================
=====*/
-- 5.a)++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++
create or replace function LAB_FCT_PRIX_MOYEN_ACHAT (P_I_NO_ARTICLE
number)
return number is
V_MNT_PRIX_MOYEN_ACH number (6,2);
begin
select nvl(avg(MNT_PRIX_ACH), 0) into V_MNT_PRIX_MOYEN_ACH
from LAB_ACHETER
where NO_ARTICLE = P_I_NO_ARTICLE;
return V_MNT_PRIX_MOYEN_ACH;
end;
-- 5.b)++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++
select LAB_FCT_PRIX_MOYEN_ACHAT (3) from dual;
-- 5.c)++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++
select LAB_FCT_PRIX_MOYEN_ACHAT (4) from dual;
-- 5.d)++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++
select LAB_FCT_PRIX_MOYEN_ACHAT (9) from dual;
/
*========================================================================
======
QUESTION 6.
=========================================================================
=====*/
-- 6.a)++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++
create or replace trigger LAB_TRG_AUI_ACHETER after
update or insert on LAB_ACHETER
for each row
declare
V_NB_ARTICLE_EN_PERTE number;
begin
select count(NO_ARTICLE) into V_NB_ARTICLE_EN_PERTE
from LAB_ARTICLE
where NO_ARTICLE = :new.NO_ARTICLE and :new.MNT_PRIX_ACH >
MNT_PRIX_INVENT_ART;
if V_NB_ARTICLE_EN_PERTE > 0 then
raise_application_error(-20000, 'Le prix d''achat au
fournisseur ne peut pas
tre suprieur au prix d''inventaire, sinon il y
aura perte');
end if;
end;
-- 6.b)++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++
insert into LAB_ACHETER (NO_FOURNISSEUR, NO_ARTICLE, MNT_PRIX_ACH,
DELAI_ACH)
values (130, 3, 47.49, 15);
-- 6.c)++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++
insert into LAB_ACHETER (NO_FOURNISSEUR, NO_ARTICLE, MNT_PRIX_ACH,
DELAI_ACH)
values (125, 3, 57.49, 12);
-- 6.d)++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++
insert into LAB_ACHETER (NO_FOURNISSEUR, NO_ARTICLE, MNT_PRIX_ACH,
DELAI_ACH)
values (130, 4, 52.49, 18);
/
*========================================================================
======
QUESTION 7.
=========================================================================
=====*/
-- 7.a)++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++
select lpad('',LEVEL*2,'')||NOM_CLI as ARBRE,
NO_CLIENT,
NO_CLIENT_PARRAIN,
sys_connect_by_path(NOM_CLI, '/') as CHEMIN,
LEVEL as NIVEAU
from LAB_CLIENT
connect by prior NO_CLIENT = NO_CLIENT_PARRAIN
start with NO_CLIENT_PARRAIN is null;
-- 7.b)++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++
select substr(NOM_CLI,1,30) as ARBRE,
NO_CLIENT,
NO_CLIENT_PARRAIN,
sys_connect_by_path(NOM_CLI, '/') as CHEMIN,
LEVEL as NIVEAU
from LAB_CLIENT
connect by prior NO_CLIENT = NO_CLIENT_PARRAIN
start with NO_CLIENT_PARRAIN is null;
-- 7.c)++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++
select substr(NOM_CLI,1,30) as ARBRE,
NO_CLIENT,
NO_CLIENT_PARRAIN,
substr(NOM_CLI,1,60) as CHEMIN,
LEVEL as NIVEAU
from LAB_CLIENT
connect by prior NO_CLIENT = NO_CLIENT_PARRAIN
start with NO_CLIENT_PARRAIN is null;