Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Probleme avec une requete PLPgSQL

2 réponses
Avatar
Sébastien Baguette
Bonjour...

Je cherche à effectuer une procedure stockée écrite en Pl/PgSQL.

Cette procédure stockée devrait me permettre de compter les occurences de
caractères ([a-z][0-9]#%$) dans une chaine, afin de me simplifier certains
traitements futurs.

Malheureusement, lorsque j'essaye d'executer cette procédure, j'obtiens
l'erreur suivante :

ERROR:  syntax error at or near "LOOP"
CONTEXT:  compile of PL/pgSQL function "add_chars" near line 26


Il y aurait donc une erreur, qui pourrait se situer aux alentours de mon
END LOOP; . Hélas, j'ai beau chercher, je ne parviens pas à mettre la main
sur ma coquille...

Je poste donc ici en espérant que quelqu'un sera plus inspiré que moi...

D'avance un tout grand merci ! :)

8<------------------------------------------------------------------------->8

CREATE TABLE db_part_chars
(
    id_part integer NOT NULL,
    id_fourn integer NOT NULL,
    chars_nb VARCHAR(255)
);


CREATE FUNCTION add_chars(integer, integer, text) RETURNS void
    AS '
  DECLARE
    new_id_part ALIAS FOR $1;
    new_id_fourn ALIAS FOR $2;
    ref_a_nu ALIAS FOR $3;
    col INTEGER;
    chaine text;
  BEGIN
    chaine := repeat(chr(0), 39);
    INSERT INTO db_part_chars(id_part, id_fourn)
                           VALUES (new_id_part, new_id_fourn);

    FOR pos IN 1..char_length(ref_a_nu) LOOP
      col := ascii(substr(ref_a_nu, pos, 1));
      IF (col >= 35 AND col <= 37) THEN
        col := col + 2;
        chaine := substr(chaine, 1, col - 1) ||
          chr(ascii(substr(chaine, col, 1)) + 1) || substr(chaine, col + 1);
      ELSE IF (col >= 48 AND col <= 57) THEN
        col := col - 21;
        chaine := substr(chaine, 1, col - 1) ||
          chr(ascii(substr(chaine, col, 1)) + 1) || substr(chaine, col + 1);
      ELSE IF (col >= 65 AND col <= 90) THEN
        col := col - 64;
        chaine := substr(chaine, 1, col - 1) ||
          chr(ascii(substr(chaine, col, 1)) + 1) || substr(chaine, col + 1);
      ELSE IF (col >= 97 AND col <= 122) THEN
        col := col - 96;
        chaine := substr(chaine, 1, col - 1) ||
          chr(ascii(substr(chaine, col, 1)) + 1) || substr(chaine, col + 1);
      END IF;
    END LOOP;

    UPDATE db_part_chars SET chars_nb=chaine WHERE id_part=new_id_part;
    RETURN;
  END;
'
    LANGUAGE plpgsql;


--
Sébastien Baguette
sebaguette_ng@netcourrier.com

2 réponses

Avatar
ts
"S" == Sébastien Baguette writes:











S>       ELSE IF (col >= 48 AND col <= 57) THEN

Remplacez tous vos 'ELSE IF' par 'ELSIF'

--

Guy Decoux
Avatar
Sébastien Baguette
ts wrote:

"S" == Sébastien Baguette writes:











S>       ELSE IF (col >= 48 AND col <= 57) THEN

Remplacez tous vos 'ELSE IF' par 'ELSIF'



En effet, c'était bien cela. Mon erreur est due à la même coquille dans mon
ouvrage de référence, ce qui fait que j'ai mémorisé la faute...

Un tout grand merci à vous ! :)

--
Sébastien Baguette