utilser une fonction dans un trigger
bonsoir a tous
j'ai crée une fonction qui renvoi un resultat de type NUMBER ,
et je doit l'utiliser dans un trigger , mais je connai pas la synatxe avec pl/sql
ma fonction est nommée : Qnt_Stock
le trigger est :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
create or replace trigger maj_MntTotal_stock
after insert on lignecommande
declare
stk_p produit.tockprod%type;
id_p produit.idproduit%type;
mnt_c commande.montanttotalcom%type;
qnt_p lignecommande.quantiteprod%type;
for each row
begin
select montanttotalcom into mnt_c from commande ;
select (stockprod) into stk_p from produit;
EXCEPTION
when stk_p = qnt_stock(:new.idproduit) < :new.quantiteprod; then
insert into ligneerreur (idcommande, idlig, idproduit, quantiteprod, stockprod) values ( :new.idcommande, :new.idlig, :new.idproduit, :new.quantiteprod, stk_p);
end ;
/ |
le trigger n'est pas complé , je veux commencer par la partie exception .
sous oracle le trigger est crée avec les erreur suivantes :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
SQL> create or replace trigger maj_MntTotal_stock
2
3 after insert on lignecommande
4
5 declare
6
7 stk_p produit.tockprod%type;
8 id_p produit.idproduit%type;
9 mnt_c commande.montanttotalcom%type;
10 qnt_p lignecommande.quantiteprod%type;
11
12 for each row
13 begin
14 select montanttotalcom into mnt_c from commande ;
15 select (stockprod) into stk_p from produit;
16
17
18
19 EXCEPTION
20 when stk_p = qnt_stock(:new.idproduit) < :new.quantiteprod; then
21 insert into ligneerreur (idcommande, idlig, idproduit, quantiteprod, stockprod) values ( :new.i
dcommande, :new.idlig, :new.idproduit, :new.quantiteprod, stk_p);
22 end ;
23 /
Avertissement : Déclencheur créé avec erreurs de compilation.
SQL> show errors
Erreurs pour TRIGGER MAJ_MNTTOTAL_STOCK :
LINE/COL ERROR
-------- -----------------------------------------------------------------
8/1 PLS-00103: Symbole "FOR" rencontré à la place d'un des symboles
suivants :
begin function package pragma procedure subtype type use
<an identifier> <a double-quoted delimited-identifier> form
current cursor |
Merci de votre aide