Ex1 Fonction

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

1

2 CREATE OR REPLACE FUNCTION nombre_clients (


3 ville IN client.cville%TYPE := 'Casa',
4 mag IN magazine.mnom%TYPE := 'JeuneAfrique'
5 ) RETURN number IS
6 nb number;
7 record_not_exists EXCEPTION;
8 BEGIN
9 SELECT
10 COUNT(*)
11 INTO nb
12 FROM
13 client c
14 JOIN abonnement a ON ( c.cid = a.cid )
15 JOIN magazine m ON ( m.mid = a.mid )
16 WHERE
17 mnom = 'JeuneAfrique'
18 AND cville = ville
19 AND start_date > TO_DATE('31/08/2010 23:59:59', 'DD/MM/YYYY HH24:MI:SS');
20
21 IF nb = 0 THEN
22 RAISE record_not_exists;
23 ELSE
24 RETURN nb;
25 END IF;
26 EXCEPTION
27 WHEN record_not_exists THEN
28 dbms_output.put_line('Pas d abonnés dans la ville de ' || ville);
29 RETURN 0;
30 END;
31
32
33
34
35
36
37 --Exercice 2
38
39 CREATE OR REPLACE PROCEDURE moyenneage (
40 agelim IN NUMBER
41 ) IS
42 CURSOR cs (
43 age_limite NUMBER
44 ) IS SELECT
45 departement AS dnom,
46 COUNT(*) AS nb
47 FROM
48 employee
49 WHERE
50 age > age_limite
51 GROUP BY
52 departement;
53 begin
54 for dept in cs(agelim)
55 loop
56 dbms_output.put_line(dept.dnom || ' ' || dept.nb) ;
57 end for;
58 end;
59 /

You might also like