IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SQL Procédural MySQL Discussion :

Procédure syntaxe error


Sujet :

SQL Procédural MySQL

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    472
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 472
    Points : 121
    Points
    121
    Par défaut Procédure syntaxe error
    Bonjour,

    Je fait appel à vous car j'ai écris une procédure, et je n'arrive pas à trouver le problème. J'obtiens toujours le message :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PROCEDURE maj_desc ()
    BEGIN
    DECLARE v_aioseop_description varchar(200)' at line 1
    Voici le code de ma procédure :
    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 OR REPLACE PROCEDURE maj_desc ()
    BEGIN
    DECLARE v_aioseop_description varchar(200);
    DECLARE v_aioseop_title varchar(100);
    DECLARE v_ville varchar(100);
    DECLARE v_metier varchar(100);
    DECLARE c_f CURSOR FOR SELECT post_id, meta_value FROM `wp_postmeta` WHERE `meta_key` LIKE '_aioseop_description' AND meta_value LIKE 'Pr' for update;
    DECLARE v_post_id wp_postmeta.post_id%type;
    DECLARE v_meta_value wp_postmeta.meta_value%type;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
     
      open c_f;
      REPEAT
        fetch c_f into v_post_id, v_meta_value;
        IF NOT done THEN
    		/*recherche des valeurs*/
    		SELECT `meta_value` FROM `wp_postmeta` WHERE `meta_key` LIKE '_aioseop_title' AND `post_id` = v_post_id INTO v_aioseop_title;
    		SELECT `meta_value` FROM `wp_postmeta` WHERE `meta_key` LIKE 'ville' AND `post_id` = v_post_id INTO v_ville;
    		SELECT `meta_value` FROM `wp_postmeta` WHERE `meta_key` LIKE 'metier' AND `post_id` = v_post_id INTO v_metier;
    		/*update de la description*/
    		update `wp_postmeta` set `meta_value`=" Présentation de " || v_aioseop_title || ", " || v_metier || " de la ville " || v_ville where current of c_f AND `meta_key` LIKE  '_aioseop_description';
    	END IF;
    	UNTIL done END REPEAT;
     
      close c_f;
    end;
    /
    Merci de votre aide !

  2. #2
    Membre expérimenté
    Homme Profil pro
    Développeur C++
    Inscrit en
    Avril 2012
    Messages
    771
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur C++
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2012
    Messages : 771
    Points : 1 631
    Points
    1 631
    Par défaut
    Bonsoir,

    il me semble que MySQL n'intègre pas le REPLACE,

    tu va devoir passer par :
    Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    DROP PROCEDURE IF EXISTS nomProcedure;
    CREATE PROCEDURE nomProcedure
    ...
    une réponse vous a permis d'avancer ?

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    472
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 472
    Points : 121
    Points
    121
    Par défaut
    Merci, modifié mais nouvelle erreur...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3
    Et je dois dire que cela n'aide pas beaucoup....surtout que ma ligne 3 c'est "BEGIN"

  4. #4
    Membre expérimenté
    Homme Profil pro
    Développeur C++
    Inscrit en
    Avril 2012
    Messages
    771
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur C++
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2012
    Messages : 771
    Points : 1 631
    Points
    1 631
    Par défaut
    A tu bien changé le delimiter ?

    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
    delimiter //
    DROP PROCEDURE IF EXISTS maj_desc//
    CREATE OR REPLACE PROCEDURE maj_desc ()
    BEGIN
        DECLARE v_aioseop_description varchar(200);
        DECLARE v_aioseop_title varchar(100);
        DECLARE v_ville varchar(100);
        DECLARE v_metier varchar(100);
        DECLARE c_f CURSOR FOR SELECT post_id, meta_value FROM `wp_postmeta` WHERE `meta_key` LIKE '_aioseop_description' AND meta_value LIKE 'Pr' FOR UPDATE;
        DECLARE v_post_id wp_postmeta.post_id%type;
        DECLARE v_meta_value wp_postmeta.meta_value%type;
        DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
     
        open c_f;
            REPEAT
                fetch c_f INTO v_post_id, v_meta_value;
                    IF NOT done THEN
    	        	/*recherche des valeurs*/
    		        SELECT `meta_value` FROM `wp_postmeta` WHERE `meta_key` LIKE '_aioseop_title' AND `post_id` = v_post_id INTO v_aioseop_title;
            		SELECT `meta_value` FROM `wp_postmeta` WHERE `meta_key` LIKE 'ville' AND `post_id` = v_post_id INTO v_ville;
    	        	SELECT `meta_value` FROM `wp_postmeta` WHERE `meta_key` LIKE 'metier' AND `post_id` = v_post_id INTO v_metier;
    		        /*update de la description*/
            		UPDATE `wp_postmeta` SET `meta_value`=" Présentation de " || v_aioseop_title || ", " || v_metier || " de la ville " || v_ville WHERE current of c_f AND `meta_key` LIKE  '_aioseop_description';
            	END IF;
    	    UNTIL done END REPEAT;
          close c_f;
    end//
    une réponse vous a permis d'avancer ?

  5. #5
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    472
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 472
    Points : 121
    Points
    121
    Par défaut
    En réalité je pense que j'avais un problème avec ma version de phpMyAdmin, j'ai donc changé de version pour une Version: 4.0.0;

    J'arrive donc bien maintenant à créer ma procédure, malheureusement j'ai des problèmes dans l'execution de celle-ci à présent.

    Pour débugguer je voulais utiliser des : Afin d'afficher les différentes étapes d'execution.
    Mais visiblement cela ne fonctionne pas sous phpMyAdmin.

    Comment palier à cela ?

  6. #6
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    472
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 472
    Points : 121
    Points
    121
    Par défaut
    Je progresse un peu, visiblement l'option du fichier config.inc.php était en cause :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $cfg['Servers'][$i]['extension'] = 'mysqli';
    Malgrès tout j'ai toujours un problème.

    Voici mon code actualisé :

    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
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    delimiter //
    DROP PROCEDURE IF EXISTS maj_desc_test//
    CREATE PROCEDURE maj_desc_test ()
    BEGIN
    DECLARE no_more_posts int;
    DECLARE v_count int;
    DECLARE v_temp longtext;
    DECLARE v_aioseop_description longtext;
    DECLARE v_aioseop_title longtext;
    DECLARE v_ville longtext;
    DECLARE v_metier longtext;
    DECLARE v_post_id bigint(20);
    DECLARE v_meta_value longtext;
    DECLARE c_f CURSOR FOR SELECT post_id, meta_value FROM `wp_postmeta` WHERE `meta_key` LIKE '_aioseop_description' AND meta_value LIKE 'Pr' for update;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_posts=1;
     
    SET no_more_posts=0;
     Select 'START \n';
      open c_f;
    	post_loop:WHILE(no_more_posts=0) DO
     
        fetch c_f into v_post_id, v_meta_value;
    	SET v_count := 0;
     
    		SET v_count := v_count + 1;
    		/*recherche des valeurs*/
    		SELECT `meta_value` FROM `wp_postmeta` WHERE `meta_key` LIKE '_aioseop_title' AND `post_id` = v_post_id INTO v_aioseop_title;
    		SELECT `meta_value` FROM `wp_postmeta` WHERE `meta_key` LIKE 'ville' AND `post_id` = v_post_id INTO v_ville;
    		SELECT `meta_value` FROM `wp_postmeta` WHERE `meta_key` LIKE 'metier' AND `post_id` = v_post_id INTO v_metier;
    		/*update de la description*/
     
    		SET v_temp := CONCAT("Présentation de ",v_aioseop_title,", ",v_metier," de la ville ",v_ville);
     
    		If v_temp IS NOT NULL Then
    			update `wp_postmeta` set `meta_value`= v_temp WHERE `post_id` = v_post_id  AND `meta_key` LIKE  '_aioseop_description';
    			SELECT CONCAT('N°',v_count,' : ',v_temp,'\n');
    		ELSE
    			SELECT CONCAT("Erreur sur Post N°",v_post_id);
    		End IF;
     
    		IF no_more_posts THEN
    			select "sortie de boucle";
    			LEAVE post_loop;
    		END IF;
     
    	END WHILE post_loop;
      close c_f;
      SET no_more_posts=0;
      Select 'STOP \n';
    end//
    DELIMITER ;
    Lorsque j'execute la requete du cursor unitairement, je trouve plus de 1000 résultats, et lorsque j'execute ma procédure, je vois apparaitre uniquement "START" et puis plus rien...

    Avez-vous une idée ?

  7. #7
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    472
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 472
    Points : 121
    Points
    121
    Par défaut
    Je relance le sujet, je suis toujours bloqué sur cette procédure...

  8. #8
    Membre habitué Avatar de hiul dragonfel
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    199
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 199
    Points : 155
    Points
    155
    Par défaut
    salut

    c'est quoi le FOR UPDATE à le fin de ta requête ?
    Le langage de programmation le plus vieux, le plus optimiser et le plus efficace est l'ADN quelqu'un d'extrêmement intelligent l'a obligatoirement inventé.

Discussions similaires

  1. [Configuration] Problème après l'installation (Parse error: syntax error,..)
    Par beur dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 8
    Dernier message: 21/03/2006, 14h08
  2. syntax error
    Par ludovik dans le forum C
    Réponses: 5
    Dernier message: 18/03/2006, 21h32
  3. Syntax error
    Par vincedjs dans le forum Langage
    Réponses: 3
    Dernier message: 01/02/2006, 16h58
  4. Syntax Error / Questions
    Par kedare dans le forum Général Python
    Réponses: 15
    Dernier message: 12/09/2005, 14h05
  5. "vector" provoque "syntax error", malgré
    Par seenkay dans le forum Autres éditeurs
    Réponses: 5
    Dernier message: 24/08/2003, 03h21

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo