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 :

Erreur à la création de la procédure stockée


Sujet :

SQL Procédural MySQL

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Février 2004
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2004
    Messages : 12
    Par défaut Erreur à la création de la procédure stockée
    Bonjour,
    Je veux créer cette 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
     
    DELIMITER //
    DROP PROCEDURE IF EXISTS `GetCumul` //
    CREATE PROCEDURE `GetCumul`(IN datedeb DATE)
    BEGIN
     
    DECLARE @minhpjb int ;
    DECLARE @minhcjb int ; 
     
    @minhpjb :=0;
    @minhcjb :=0;
     
    @minhpjb:=SELECT MIN( `BBRHPJB` )	FROM `teleinfo`	WHERE rec_date >= datedeb AND (`BBRHCJB` <>0);		
     
    @minhcjb:=SELECT MIN( `BBRHCJB` )	FROM `teleinfo`	WHERE rec_date >= datedeb AND (`BBRHCJB` <>0);
     
    	SELECT DISTINCT rec_date, rec_time, max(`BBRHPJB`) - @minhpjb AS VarCumul, PTEC
    	FROM `teleinfo`
    	GROUP BY rec_date, PTEC
    	having rec_date >= datedeb;
    union
    	SELECT DISTINCT rec_date, rec_time, max(`BBRHCJB`) - @minhcjb AS VarCumul, PTEC
    	FROM `teleinfo`
    	GROUP BY rec_date, PTEC
    	having rec_date >= datedeb;
    END //
    DELIMITER ;
    Mais j'ai ce message :
    ERROR 1064 (42000) at line 3: 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 '@minhpjb int ;
    DECLARE @minhcjb int ;

    @minhpjb :=0;
    @minhcjb :=0;

    @minhpjb:=S' at line 4

    Depuis plusieurs heures, je butte... en touche

  2. #2
    Expert confirmé
    Avatar de qi130
    Homme Profil pro
    Expert Processus IT
    Inscrit en
    Mars 2003
    Messages
    3 947
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 64
    Localisation : France

    Informations professionnelles :
    Activité : Expert Processus IT
    Secteur : Finance

    Informations forums :
    Inscription : Mars 2003
    Messages : 3 947
    Par défaut
    DECLARE ne peut être utilisé dans un bloc BEGIN ... END
    Cf. http://dev.mysql.com/doc/refman/5.0/fr/declare.html

  3. #3
    Membre éprouvé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2011
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2011
    Messages : 55
    Par défaut
    Bonjour,

    Code SQL : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    DECLARE @minhpjb int ;
    DECLARE @minhcjb int ; 
     
    SET @minhpjb =0;
    SET @minhcjb  =0;
     
    .....

    Mais tu peux aussi mettre la valeur dans la section Declare

    Code SQL : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    DECLARE @minhpjb int Default 0  ;
    DECLARE @minhcjb int Default 0 ; 
     
     
    @minhpjb:=SELECT MIN( `BBRHPJB` )	FROM `teleinfo`	WHERE rec_date >= datedeb AND (`BBRHCJB` <>0);		
     
    ....

    Bonne soirée

    Francis

  4. #4
    Membre éprouvé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2011
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2011
    Messages : 55
    Par défaut
    Et je crois que tu devrais faire un Select into ...

    Code SQL : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    SELECT MIN( `BBRHPJB` ) into @minhpjb	FROM `teleinfo`	WHERE rec_date >= datedeb AND (`BBRHCJB` <>0);

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Février 2004
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2004
    Messages : 12
    Par défaut
    Merci pour votre aide,
    Donc j'ai tenu compte de vos remarques ce qui me donne ceci :
    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
    DELIMITER //
    DROP PROCEDURE IF EXISTS `GetCumul` //
    CREATE PROCEDURE `GetCumul`(IN datedeb DATE)
    DECLARE @minhpjb bigint DEFAULT 0;
    DECLARE @minhcjb bigint DEFAULT 0; 
    BEGIN
    SELECT MIN( `BBRHPJB` )into @minhpjb	FROM `teleinfo`	WHERE rec_date >= datedeb AND (`BBRHCJB` <>0);		
    SELECT MIN( `BBRHCJB` )into @minhcjb	FROM `teleinfo`	WHERE rec_date >= datedeb AND (`BBRHCJB` <>0);
     
    	SELECT DISTINCT rec_date, rec_time, max(`BBRHPJB`) - @minhpjb AS VarCumul, PTEC
    	FROM `teleinfo`
    	GROUP BY rec_date, PTEC
    	having rec_date >= datedeb
    union
    	SELECT DISTINCT rec_date, rec_time, max(`BBRHCJB`) - @minhcjb AS VarCumul, PTEC
    	FROM `teleinfo`
    	GROUP BY rec_date, PTEC
    	having rec_date >= datedeb;
     
    END //
    DELIMITER ;
    mais j'ai ce message d'erreur :
    ERROR 1064 (42000) at line 3: 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 'DECLARE @minhpjb int DEFAULT 0;
    DECLARE @minhcjb int DEFAULT 0;

    BEGIN

    SELECT ' at line 2

  6. #6
    Expert confirmé
    Avatar de qi130
    Homme Profil pro
    Expert Processus IT
    Inscrit en
    Mars 2003
    Messages
    3 947
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 64
    Localisation : France

    Informations professionnelles :
    Activité : Expert Processus IT
    Secteur : Finance

    Informations forums :
    Inscription : Mars 2003
    Messages : 3 947
    Par défaut
    Je crois qu'il y a 1 pb de version

    Tu fournis un code où tu déclares en bigint, et l'erreur fait état du type int pour tes variables.....

  7. #7
    Membre averti
    Profil pro
    Inscrit en
    Février 2004
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2004
    Messages : 12
    Par défaut
    Citation Envoyé par qi130 Voir le message
    Je crois qu'il y a 1 pb de version

    Tu fournis un code où tu déclares en bigint, et l'erreur fait état du type int pour tes variables.....
    Oui, mais les colonne 'BBRHCJB' & 'BBRHPJB' sont de type bigint.

  8. #8
    Membre averti
    Profil pro
    Inscrit en
    Février 2004
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2004
    Messages : 12
    Par défaut
    Excuse mon message précédent, j'avais mal lu.

    Oui, c'est bien des Bigint, mais cela ne change rien, j'ai toujours ce message dans ma console linux :

    ERROR 1064 (42000) at line 3: 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 'DECLARE @minhpjb bigint DEFAULT 0;
    DECLARE @minhcjb bigint DEFAULT 0;
    BEGIN
    SEL' at line 2

  9. #9
    Membre éprouvé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2011
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2011
    Messages : 55
    Par défaut
    A mon avis, il faut mettre le BEGIN en première ligne et les DECLARE Ensuite.

  10. #10
    Membre éprouvé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2011
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2011
    Messages : 55
    Par défaut
    Cette procédure se "compile" sans erreur.

    Le problème provient des @ dans tes noms de variables lors de la déclaration.
    Pour moi, les variables @xxxx ne se déclarent pas et sont une facilité de Mysql. ( Facilité que je n'aime pas trop ).


    Code SQL : 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
     
    DELIMITER //
    DROP PROCEDURE IF EXISTS `GetCumul` //
    CREATE PROCEDURE `GetCumul`(IN datedeb DATE) 
    BEGIN
     
    Set @minhpjb = 0 ;
    Set @minhcjb = 0 ;
     
    SELECT MIN( `BBRHPJB` )INTO @minhpjb	FROM `teleinfo`	WHERE rec_date >= datedeb AND (`BBRHCJB` <>0);		
    SELECT MIN( `BBRHCJB` )INTO @minhcjb	FROM `teleinfo`	WHERE rec_date >= datedeb AND (`BBRHCJB` <>0);
     
    	SELECT DISTINCT rec_date, rec_time, max(`BBRHPJB`) - @minhpjb AS VarCumul, PTEC
    	FROM `teleinfo`
    	GROUP BY rec_date, PTEC
    	HAVING rec_date >= datedeb
    union
    	SELECT DISTINCT rec_date, rec_time, max(`BBRHCJB`) - @minhcjb AS VarCumul, PTEC
    	FROM `teleinfo`
    	GROUP BY rec_date, PTEC
    	HAVING rec_date >= datedeb;
     
    END //
    DELIMITER ;

  11. #11
    Membre averti
    Profil pro
    Inscrit en
    Février 2004
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2004
    Messages : 12
    Par défaut
    Citation Envoyé par Grandal Voir le message
    Cette procédure se "compile" sans erreur.

    Le problème provient des @ dans tes noms de variables lors de la déclaration.
    Pour moi, les variables @xxxx ne se déclarent pas et sont une facilité de Mysql. ( Facilité que je n'aime pas trop ).


    Code SQL : 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
     
    DELIMITER //
    DROP PROCEDURE IF EXISTS `GetCumul` //
    CREATE PROCEDURE `GetCumul`(IN datedeb DATE) 
    BEGIN
     
    Set @minhpjb = 0 ;
    Set @minhcjb = 0 ;
     
    SELECT MIN( `BBRHPJB` )INTO @minhpjb	FROM `teleinfo`	WHERE rec_date >= datedeb AND (`BBRHCJB` <>0);		
    SELECT MIN( `BBRHCJB` )INTO @minhcjb	FROM `teleinfo`	WHERE rec_date >= datedeb AND (`BBRHCJB` <>0);
     
    	SELECT DISTINCT rec_date, rec_time, max(`BBRHPJB`) - @minhpjb AS VarCumul, PTEC
    	FROM `teleinfo`
    	GROUP BY rec_date, PTEC
    	HAVING rec_date >= datedeb
    union
    	SELECT DISTINCT rec_date, rec_time, max(`BBRHCJB`) - @minhcjb AS VarCumul, PTEC
    	FROM `teleinfo`
    	GROUP BY rec_date, PTEC
    	HAVING rec_date >= datedeb;
     
    END //
    DELIMITER ;
    Tu as raison ,à ma grande suprise !
    Et j'ai du mal à concevoir de ne pas déclarer mes variables.

    Merci :-)

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Erreur SELECT INTO dans une procédure stockée
    Par mercure07 dans le forum SQL Procédural
    Réponses: 2
    Dernier message: 17/12/2008, 09h54
  2. création package de procédure stocké oracle
    Par ouadie99 dans le forum C#
    Réponses: 3
    Dernier message: 14/05/2008, 18h51
  3. Création d'une procédure stockée
    Par david71 dans le forum SQL
    Réponses: 5
    Dernier message: 16/01/2008, 18h45
  4. Erreur d'Exécution d'une procédure stockée
    Par h.Madjid dans le forum SQL
    Réponses: 1
    Dernier message: 05/09/2007, 20h34
  5. création triggers et procédure stockées
    Par jhons dans le forum MS SQL Server
    Réponses: 3
    Dernier message: 12/07/2006, 18h54

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