Bloc Anonyme PL/SQL: Declare

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

E xercice 1

Bloc anonyme pl/sql


select c.num_cde,c.date_cde,c.code_client,

A.désignation,A.prix,DC.qte_cde,DL.num_liv,DL.qte_liv

from Commande c,Article A,Detail_liv DL, Detail_cde DC,

Livraison L

where (C.num_cde=DC.num_cde)and(C.num_cde=L.num_cde)and

(DC.code_art=A.code_art)and(DL.code_art=A.code_art)and

(L.num_liv=DL.num_liv)and(C.date_cde between ('01-01-2020' and '31-


12-2020'))

group by c.num_cde,c.date_cde,c.code_client,

A.désignation,A.prix,DC.qte_cde,DL.num_liv,DL.qte_liv

Bloc pl/sql
Declare
v_num_cde commande.num_cde%type ;
v_date_cde commande.date_cde%type ;
v_code_client commande.code_client%type ;
v_désignation article.désignation%type ;
v_prix article.prix%type ;
v_qte_cde detail_cde.qte_cde%type ;
v_num_liv livraison.num_liv%type ;
v_qte_liv detail_liv.qte_liv%type ;
Begin
select c.num_cde,c.date_cde,c.code_client,
A.désignation,A.prix,DC.qte_cde,DL.num_liv,DL.qte_li
v into v_num_cde ,v_date_cde ,v_code_client
,v_désignation,v_prix, v_qte_cde,v_num_liv,v_qte_liv
from Commande c,Article A,Detail_liv DL, Detail_cde
DC,Livraison L
where
(C.num_cde=DC.num_cde)and(C.num_cde=L.num_cde)
and
(DC.code_art=A.code_art)and(DL.code_art=A.code_art)
and
(L.num_liv=DL.num_liv)and(C.date_cde between ('01-
01-2020' and '31-12-2020'))
group by c.num_cde,c.date_cde,c.code_client,
A.désignation,A.prix,DC.qte_cde,DL.num_liv,DL.qte_li
v
DBMS_OUTPUT.PUT_LINE('le numero de
commande :' || v_num_cde || 'date commande:' ||
v_date_cde ||' le code client est :' || v_code_client ….);
End ;

E xercice 2
Exemple
Ecrire une procédure qui prend en paramètre
l’année et détermine comme résultats le code et la
désignation du client qui a réalisé le plus grand
chiffre d’affaires durant cette année.
article(code_art, designation, qte_stock, prix)
client(code_client,designation,adresse)
commande(num_cde,date_cde,#code_client)
detail_cde(#num_cde,#code_art,qte_cde)
livraison(num_liv,date_liv,#num_cde)
detail_liv(#num_liv,#code_art,qte_liv)
create or replace procedure meilleur_client
(p_annee number,p_code out client.code_client
%type,p_design out client.designation%type) is
cursor c_client is
select
cl.code_client,designation,sum(qte_cde*prix) CA
from detail_cded,article a, commande c, client cl
where d.code_art=a.code_art
and d.num_cde=c.num_cde
and c.code_client=cl.code_client
and to_number(to_char(date_cde,’yyyy’))=p_annee
group by cl.code_client,designation
order by CA desc;
v_CA number;
begin
open c_client;
fetch c_client into p_code, p_design,v_CA;
close c_client;
end Meilleur_client;
E xercice 3
create or replace trigger maj_stock
after update or delete or insert on detail_cde
for each row
begin
if updating then
update article
set qte_stock = qte_stock + :old.qte_stock
-:new.qte_stock
where code_art = :old.code_art;
elsif deleting then
update article
set qte_stock = qte_stock + :old.qte_stock
where code_art = :old.code_art;
else
update article
set qte_stock=qte_stock - :new.qte_cde
where code_art=:new.code_art;
end if;
end maj_stock;

You might also like