Bonjour,

Je débute en PL/SQL et je bute sur un problème apparemment tout bête depuis plusieurs jours.... Voilà mon problème, je cherche à créer une fonction qui ajoute +1 à une variable à chaque fois qu'elle est appellée (des mathématiques de haut vol). La fonction donc doit me renvoyer une valeur, et changer la valeur de ma variable externe à la fonction, au cas où ce soit la cause "ELSE" qui soit appellée.

La deuxième partie du script focntionne, je l'ai laissé juste pour que vous puissiez voir plus clairement mon objectif.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
-- Création de la fonction ou remplacement si elle n'existe pas déjà --
create or replace function NUM_TRONC return number
is 
  result number;
  ma_variable number := @INCH;
BEGIN
   result := ma_variable + 1;
   DEFINE @INCH := result;
 
   RETURN (result);
END;
-- Execution de la création des tronçons --
 
DEFINE CAT_ELS_PREC=( select CAT_ELS from POPULATION_RAPPORT_comp deux where deux.POP_RPT_PK_H = (select POP_RPT_PK_H-10 from POPULATION_RAPPORT_comp un where deux.FID_bis=un.fid_bis-1) and deux.FID_bis=trois.fid_bis-1)
DEFINE PRO_ELS_PREC=( select PRO_ELS from POPULATION_RAPPORT_comp deux where deux.POP_RPT_PK_H = (select POP_RPT_PK_H-10 from POPULATION_RAPPORT_comp un where deux.FID_bis=un.fid_bis-1) and deux.FID_bis=trois.fid_bis-1)
DEFINE INCH=(1);
UPDATE POPULATION_RAPPORT_comp trois
SET trois.N_TRONC_HOM_ELS = (
  CASE 
    WHEN CAT_ELS not like &CAT_ELS_PREC or PRO_ELS not like &PRO_ELS_PREC THEN NUM_TRONCON
    ELSE &INCH
  END
) ;
Merci par avance pour votre aide et bonne journée.