Bonjour,

ci dessous un trigger qui met a jour la taille du champ N_COMPTE lors de insertion en ajoutant des 0 a la fin pour avoir une chaine de n caractere defini selon le champs width de table params

exp: si utilisateur saisi 253 dans application le champ insérer dans la table est 25300000 (si width=8 caracteres )

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
24
25
26
27
 
CREATE TRIGGER NC_NCPT_WIDTH FOR C_PLAN ACTIVE BEFORE INSERT POSITION 0 AS
DECLARE VARIABLE cptwdth integer;
DECLARE VARIABLE ileng integer;
DECLARE VARIABLE chaine varchar(14);
begin
SELECT P_N_COMPTE_WIDTH FROM C_PARAMS into :cptwdth; 
if (:cptwdth=0) then
BEGIN
IF ( NEW.N_COMPTE_P IS NULL ) THEN
   NEW.N_COMPTE_P=NEW.N_COMPTE_P;
END
ELSE
if (:cptwdth>1) then
 begin 
   IF ( NEW.N_COMPTE_P IS NULL ) THEN  
    BEGIN         
      ileng = CHAR_LENGTH(NEW.N_COMPTE_P);
       while (ileng<cptwdth) do  
       begin 
        chaine =  chaine||'0'; 
        ileng=ileng+1; 
       end
      NEW.N_COMPTE_P=chaine;
    END    
 end   
end
ou
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
 
CREATE TRIGGER C_CPT_WIDTH FOR C_PLAN ACTIVE BEFORE INSERT POSITION 0 AS
DECLARE VARIABLE cptwdth integer;
begin
SELECT P_N_COMPTE_WIDTH FROM C_PARAMS into :cptwdth; 
if (:cptwdth=0) then
BEGIN
IF ( NEW.N_COMPTE_P IS NULL ) THEN
   NEW.N_COMPTE_P=NEW.N_COMPTE_P;
END
ELSE
if (:cptwdth>1) then
 begin   
   IF ( NEW.N_COMPTE_P IS NULL ) THEN  
    BEGIN    
     NEW.N_COMPTE_P=RPAD(NEW.N_COMPTE_P, :cptwdth, '0');       
    END   
 end   
end
après ajout dans la table C_PLAN il n'ya pas de changement dans le champ N_COMPTE