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

DB2 Discussion :

Procédure stockée dans fonction


Sujet :

DB2

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 60
    Points : 31
    Points
    31
    Par défaut Procédure stockée dans fonction
    Bonjour a tous,

    Mon problème est que je n'arrive pas a transférer ma variable :

    Voici ma procédure :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    CREATE PROCEDURE cherche2 
    	(ID VARCHAR(36), OUT GR INTEGER) 
    	 READS SQL DATA 
    	BEGIN 
    	...
    	RETURN GR;
    Ma fonction (elle doit se servir de ma procédure) :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    CREATE FUNCTION cherche(ID VARCHAR(36)) 
    	RETURNS INTEGER 
    	BEGIN ATOMIC 
    	DECLARE GR INTEGER; 
    	call cherche2(ID, GR); 
    	RETURN GR;  -> ici ce situe l'erreur
    	END
    Je ne sais pas comment récupérer la variable GR dans ma procédure afin de la transmettre dans ma fonction et la retourner.

  2. #2
    Membre éprouvé
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    821
    Détails du profil
    Informations personnelles :
    Âge : 54
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2008
    Messages : 821
    Points : 1 084
    Points
    1 084
    Par défaut
    Que viens faire ton RETURN dans ta procédure ?????
    Enlève le

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 60
    Points : 31
    Points
    31
    Par défaut
    je l'ai mis pour pouvoir le faire transmettre a la fonction.
    J'ai essayé a la place SET GR = 1; mais j'ai toujours se problème.
    PS: y'a t'il un moyen de mettre un curseur dans une fonction ??

  4. #4
    Membre éprouvé
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    821
    Détails du profil
    Informations personnelles :
    Âge : 54
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2008
    Messages : 821
    Points : 1 084
    Points
    1 084
    Par défaut
    Tu fais ce que tu veux dans une fonction, aucun problème pour déclarer et utiliser un curseur.

  5. #5
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 60
    Points : 31
    Points
    31
    Par défaut
    J'ai essayé de mettre un cureur dans ma fonction :
    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
    CREATE FUNCTION CHERCHE
     (ID VARCHAR(36), USERS VARCHAR(250), PERMS VARCHAR(250)) 
    		RETURNS INTEGER
    		 BEGIN ATOMIC
    		DECLARE ALLUSERS VARCHAR(250); 
    		DECLARE ALLPERMS VARCHAR(250); 
    		DECLARE FIRST INTEGER; 
    		DECLARE CURID VARCHAR(36); 
    		DECLARE NEWID VARCHAR(36); 
    		DECLARE GR INTEGER;
    		DECLARE PE VARCHAR(250); 
    		DECLARE US VARCHAR(250); 
    		DECLARE v_sqlstatus INTEGER DEFAULT 0; 
    		SET ALLUSERS = '%' || USERS || '%'; 
    		SET ALLPERMS = '%' || PERMS || '%'; 
    		SET FIRST = 1; 
    		SET CURID = ID; 
    		WHILE CURID IS NOT NULL DO 
    		DECLARE CC CURSOR FOR 
    		SELECT GRANT, PERMISSION, USER FROM ACLS 
    		WHERE ACLS.ID = CURID ORDER BY POS; 
    		DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_sqlstatus = 1; 
    		 OPEN CC; 
    		   REPEAT 
    			FETCH FROM CC INTO GR, PE, US; 	
                                             IF ALLUSERS LIKE ('%' || US || '%') AND ALLPERMS LIKE ('%' || PE || '%') THEN
                                                CLOSE CC; 	 
                                                  RETURN GR; 
                                          END IF;
    			  UNTIL (v_sqlstatus = 1) END REPEAT;
    		END WHILE; 
    	CLOSE CC;
    		SELECT parentid INTO newid FROM hierarchy WHERE hierarchy.id = curid; 
    		         IF FIRST = 1 AND NEWID IS NULL THEN 
    			SELECT versionableid INTO newid FROM versions WHERE versions.id = curid; 
    		          END IF; 
    			SET FIRST = 0; 
    			SET CURID = NEWID; 				                                RETURN 0;
    				 END
    mais j'ai cette erreur :
    An unexpected token "DECLARE CC CURSOR FOR
    SELECT " was found following "S NOT NULL DO
    ". Expected tokens may include: "<values>".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.8.86

  6. #6
    Membre éprouvé
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    821
    Détails du profil
    Informations personnelles :
    Âge : 54
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2008
    Messages : 821
    Points : 1 084
    Points
    1 084
    Par défaut
    Essaye plutôt :

    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 FUNCTION CHERCHE
     (ID VARCHAR(36), USERS VARCHAR(250), PERMS VARCHAR(250)) 
    		RETURNS INTEGER
     
    		DECLARE ALLUSERS VARCHAR(250); 
    		DECLARE ALLPERMS VARCHAR(250); 
    		DECLARE FIRST INTEGER; 
    		DECLARE CURID VARCHAR(36); 
    		DECLARE NEWID VARCHAR(36); 
    		DECLARE GR INTEGER;
    		DECLARE PE VARCHAR(250); 
    		DECLARE US VARCHAR(250); 
    		DECLARE v_sqlstatus INTEGER DEFAULT 0; 
     
    		DECLARE CC CURSOR FOR 
    		SELECT GRANT, PERMISSION, USER FROM ACLS 
    		WHERE ACLS.ID = CURID ORDER BY POS; 
     
    		DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_sqlstatus = 1; 
     
     
    		SET ALLUSERS = '%' || USERS || '%'; 
    		SET ALLPERMS = '%' || PERMS || '%'; 
    		SET FIRST = 1; 
    		SET CURID = ID; 
     
    ....
    Il te faut tes déclaratives dans l'ordre

    Exemple d'une 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
    28
    29
    30
    CREATE PROCEDURE CREDITP
    (IN i_perinc DECIMAL(3,2), 
    OUT o_numrec DECIMAL(5,0)) 
    LANGUAGE SQL
    BEGIN ATOMIC 
    DECLARE proc_cusnbr CHAR(5);
    DECLARE proc_cuscrd DECIMAL(11,2);
    DECLARE numrec DECIMAL(5,0);
    DECLARE at_end INT DEFAULT 0;
    DECLARE not_found
    CONDITION FOR '02000';
    DECLARE c1 CURSOR FOR
    SELECT cusnbr, cuscrd
    FROM ordapplib.customer;
    DECLARE CONTINUE HANDLER FOR not_found
    SET at_end = 1;
    SET numrec = 0;
    OPEN c1;
    FETCH c1 INTO proc_cusnbr, proc_cuscrd;
    WHILE at_end = 0 DO
    SET proc_cuscrd = proc_cuscrd +(proc_cuscrd * i_perinc);
    UPDATE ordapplib.customer
    SET cuscrd = proc_cuscrd
    WHERE CURRENT OF c1;
    SET numrec = numrec + 1;
    FETCH c1 INTO proc_cusnbr, proc_cuscrd;
    END WHILE;
    SET o_numrec = numrec;
    CLOSE c1;
    END

  7. #7
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 60
    Points : 31
    Points
    31
    Par défaut
    J'ai suivi ton conseil mais j'ai toujours une erreur de curseur :
    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
    CREATE FUNCTION CHERCHER
    	(ID VARCHAR(36), USERS VARCHAR(250), PERMS VARCHAR(250)) 
    				   RETURNS INTEGER
    				   BEGIN ATOMIC
     
    				   DECLARE ALLUSERS VARCHAR(250); 
    				   DECLARE ALLPERMS VARCHAR(250); 
    				   DECLARE FIRST INTEGER; 
    				   DECLARE CURID VARCHAR(36); 
    				   DECLARE NEWID VARCHAR(36); 
    				   DECLARE GR INTEGER;
    				   DECLARE PE VARCHAR(250); 
    				   DECLARE US VARCHAR(250); 
    				   DECLARE v_sqlstatus INTEGER DEFAULT 0; 
     
    				   DECLARE CC CURSOR FOR 
    				   SELECT GRANT, PERMISSION, USER 
    				   FROM ACLS 
    				   WHERE ACLS.ID = CURID
    				   ORDER BY POS; 
     
    				   DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_sqlstatus = 1; 
     
     
    				     SET ALLUSERS = '%' || USERS || '%'; 
    				     SET ALLPERMS = '%' || PERMS || '%'; 
    				     SET FIRST = 1; 
    				     SET CURID = ID; 
     
    				     WHILE CURID IS NOT NULL DO 
     
    				       OPEN CC; 
    				      	 REPEAT 
    				         FETCH FROM CC INTO GR, PE, US; 
    				 	  					IF ALLUSERS LIKE ('%' || US || '%') AND ALLPERMS LIKE ('%' || PE || '%') THEN	
    				      						CLOSE CC; 
    				       					RETURN GR; 
    				     					END IF;
    				      	 UNTIL (v_sqlstatus = 1) END REPEAT;
    				      	END WHILE; 
    				       CLOSE CC;
     
    				      SELECT parentid INTO newid FROM hierarchy WHERE hierarchy.id = curid; 
    				       IF FIRST = 1 AND NEWID IS NULL THEN 
    				         SELECT versionableid INTO newid FROM versions WHERE versions.id = curid; 
    				       END IF; 
    				      	  SET FIRST = 0; 
    				      	  SET CURID = NEWID; 				     
      			     RETURN 0;
    				 END
    An unexpected token "DECLARE CC CURSOR FOR
    SELECT GRA" was found following "T 0". Expected tokens may include: "

    ".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.8.86

  8. #8
    Membre éprouvé
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    821
    Détails du profil
    Informations personnelles :
    Âge : 54
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2008
    Messages : 821
    Points : 1 084
    Points
    1 084
    Par défaut
    Ton problème vient de l'éxécution ou de la création de la fonction ?
    Je vois un return 0. Essaye un Return INT(0);

  9. #9
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 60
    Points : 31
    Points
    31
    Par défaut
    cela ne change rien

  10. #10
    Membre éprouvé
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    821
    Détails du profil
    Informations personnelles :
    Âge : 54
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2008
    Messages : 821
    Points : 1 084
    Points
    1 084
    Par défaut
    Celà ne répond pas à ma précédente question

  11. #11
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 60
    Points : 31
    Points
    31
    Par défaut
    A l'execution .
    J'ai l'erreur même en faisant ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    CREATE FUNCTION CHERCHER
    				 (ID VARCHAR(36), USERS VARCHAR(250), PERMS VARCHAR(250)) 
    				   RETURNS INTEGER 
    				   BEGIN ATOMIC
     DECLARE CC CURSOR FOR 
    				   SELECT GRANT, PERMISSION, USER 
    				   FROM ACLS 
    				   WHERE ACLS.ID = CURID
    				   ORDER BY POS;

  12. #12
    Membre éprouvé
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    821
    Détails du profil
    Informations personnelles :
    Âge : 54
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2008
    Messages : 821
    Points : 1 084
    Points
    1 084
    Par défaut
    Avant ton OPEN CC, ajoute CLOSE CC;
    Fais un STRDBG.
    Puis mets toi sous STRSQL pour lancer ta fonction.
    Copie/colle l'historique.

  13. #13
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 60
    Points : 31
    Points
    31
    Par défaut
    Je ne sais pas ce qu'est STRDBG, moi je travail sous RAD.
    Je peut te donner l'historique de RAD :
    CREATE FUNCTION CHERCHER
    (ID VARCHAR(36), USERS VARCHAR(250), PERMS VARCHAR(250))
    RETURNS INTEGER
    BEGIN ATOMIC

    DECLARE ALLUSERS VARCHAR(250);
    DECLARE ALLPERMS VARCHAR(250);
    DECLARE FIRST INTEGER;
    DECLARE CURID VARCHAR(36);
    DECLARE NEWID VARCHAR(36);
    DECLARE GR INTEGER;
    DECLARE PE VARCHAR(250);
    DECLARE US VARCHAR(250);
    DECLARE v_sqlstatus INTEGER DEFAULT 0;

    DECLARE CC CURSOR FOR
    SELECT GRANT, PERMISSION, USER
    FROM ACLS
    WHERE ACLS.ID = CURID
    ORDER BY POS;

    DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_sqlstatus = 1;

    SET ALLUSERS = '%' || USERS || '%';
    SET ALLPERMS = '%' || PERMS || '%';
    SET FIRST = 1;
    SET CURID = ID;

    WHILE CURID IS NOT NULL DO
    OPEN CC;
    REPEAT
    FETCH FROM CC INTO GR, PE, US;
    IF ALLUSERS LIKE ('%' || US || '%') AND ALLPERMS LIKE ('%' || PE || '%') THEN
    CLOSE CC;
    RETURN GR;
    END IF;
    UNTIL (v_sqlstatus = 1) END REPEAT;
    END WHILE;
    CLOSE CC;

    SELECT parentid INTO newid FROM hierarchy WHERE hierarchy.id = curid;
    IF FIRST = 1 AND NEWID IS NULL THEN
    SELECT versionableid INTO newid FROM versions WHERE versions.id = curid;
    END IF;
    SET FIRST = 0;
    SET CURID = NEWID;
    RETURN 0;
    END

    An unexpected token "DECLARE CC CURSOR FOR
    SELECT GRA" was found following "

    ". Expected tokens may include: "<space>".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.8.86

  14. #14
    Membre éprouvé
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    821
    Détails du profil
    Informations personnelles :
    Âge : 54
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2008
    Messages : 821
    Points : 1 084
    Points
    1 084
    Par défaut
    Franchement on a du mal a comprendre ce que tu veux faire au final avec ton curseur. Je me dis qu'il y a surement plus simple. Mais le problème n'est pas là.

    Essaye de créer ta fonction avec :

    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
    CREATE FUNCTION CHERCHER
    (ID VARCHAR(36), USERS VARCHAR(250), PERMS VARCHAR(250)) 
    RETURNS INTEGER 
    BEGIN ATOMIC
     
    DECLARE ALLUSERS VARCHAR(250); 
    DECLARE ALLPERMS VARCHAR(250); 
    DECLARE FIRST INTEGER; 
    DECLARE CURID VARCHAR(36); 
    DECLARE NEWID VARCHAR(36); 
    DECLARE GR INTEGER;
    DECLARE PE VARCHAR(250); 
    DECLARE US VARCHAR(250); 
    DECLARE v_sqlstatus INTEGER DEFAULT 0; 
     
    DECLARE CC CURSOR FOR 
    SELECT GRANT, PERMISSION, USER 
    FROM ACLS 
    WHERE ACLS.ID = CURID 
    ORDER BY POS; 
     
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_sqlstatus = 1; 
     
    SET ALLUSERS = '%' || USERS || '%'; 
    SET ALLPERMS = '%' || PERMS || '%'; 
    SET FIRST = 1; 
    SET CURID = ID; 
     
    CLOSE CC;
    OPEN CC; 
    FETCH CC INTO GR, PE, US; 
    RETURN INT(0);
    END
    Teste pour voir ce que celà donne.
    J'ai enlevé aussi le FROM dans ton FETCH

  15. #15
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 60
    Points : 31
    Points
    31
    Par défaut
    J'ai le problème suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    An unexpected token "DECLARE CC CURSOR FOR  
    SELECT GRANT, PER" was found following "GER DEFAULT 0".  Expected tokens may include:  "  
     
    ".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.8.86

  16. #16
    Membre éprouvé
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    821
    Détails du profil
    Informations personnelles :
    Âge : 54
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2008
    Messages : 821
    Points : 1 084
    Points
    1 084
    Par défaut
    Certains mots clés sont réservés par SQL.
    C'est le cas de GRANT, USER, etc....

    Si c'est le nom de tes colonnes de table, mets les entre guillemets.

    SELECT "GRANT", "USER" etc...

    Sinon par exemple USER récupère l'utilisateur en cours

  17. #17
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 60
    Points : 31
    Points
    31
    Par défaut
    J'ai changé de technique. J'ai fait une procédure avec le curseur et une méthode qui appelle la procédure, mais j'ai un problème au niveau de la procédure( dans les paramètres).
    En effet, si je mets out, pour la variable R, j'ai un soucis et même inout.
    Comment faire pour que la fonction retourne la bonne valeur de la variale R de la 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
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    CREATE PROCEDURE proc_cherche 
    				 (ID VARCHAR(36), USERS VARCHAR(250), PERMS VARCHAR(250), R INTEGER) 
    				   MODIFIES SQL DATA
    				   BEGIN ATOMIC
    				   DECLARE ALLUSERS VARCHAR(250); 
    				   DECLARE ALLPERMS VARCHAR(250); 
    				   DECLARE FIRST INTEGER; 
    				   DECLARE CURID VARCHAR(36) ; 
    				   DECLARE NEWID VARCHAR(36); 
    				   DECLARE GR INTEGER; 
    				   DECLARE PE VARCHAR(250); 
    				   DECLARE US VARCHAR(250); 
    				   DECLARE v_sqlstatus INTEGER DEFAULT 0; 
    				   DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_sqlstatus = 1; 
    				     SET ALLUSERS = '%%' || USERS || '%%'; 
    				     SET ALLPERMS = '%%' || PERMS || '%%';
    				     SET FIRST = 1; 
    				     SET CURID = ID; 
     
    		 	       WHILE CURID IS NOT NULL DO 	     
    				     begin
     
    				      DECLARE CC CURSOR FOR 
    				      SELECT GRANT, PERMISSION, USER FROM ACLS 
    				      WHERE ACLS.ID = CURID ORDER BY POS ; 
     
    						OPEN CC;       
     
    				      	 REPEAT 
    				         FETCH FROM CC INTO GR, PE, US;
    				 	  					IF ALLUSERS LIKE ('%%' || US || '%%') AND ALLPERMS LIKE ('%%' || PE || '%%') THEN	
    				      						CLOSE CC; 
    				      						SET R = GR; 
    				       					RETURN R; 
    				     					END IF; 
    				      	 UNTIL (v_sqlstatus = 1) END REPEAT;			   
     
    				    	CLOSE CC; 
    				      end;			    
     
    				      SELECT parentid INTO newid FROM hierarchy WHERE hierarchy.id = curid; 
    				       IF FIRST = 1 AND NEWID IS NULL THEN 
    				         SELECT versionableid INTO newid FROM versions WHERE versions.id = curid; 
    				       END IF; 
    				      	  SET FIRST = 0; 
    				      	  SET CURID = NEWID; 
    				    END WHILE; 
    				  RETURN 0;  
    				 END

    et ma fonction :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    CREATE FUNCTION cherche(ID VARCHAR(36), USERS VARCHAR(250), PERMS VARCHAR(250)) 
    				RETURNS INTEGER 
    				BEGIN ATOMIC 
    				DECLARE GR INTEGER; 
    				 CALL proc_cherche (ID, USERS, PERMS, GR); 
    				  RETURN GR; --> ici
    				 END

  18. #18
    Membre éprouvé
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    821
    Détails du profil
    Informations personnelles :
    Âge : 54
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2008
    Messages : 821
    Points : 1 084
    Points
    1 084
    Par défaut
    M'enfin, j'aurais tout mis dans la fonction.
    Je ne vois pas à quoi celà te sert de faire une fonction + 1 procédure.
    Sinon, je me répète :

    GRANT, USER etc... sont des mots clés réservés, celà ne marchera pas si tu les mets pas entre guillemets. Sauf pour USER, si tu veux récupérer l'utilisateur en cours.

    Et pourquoi mettre un RETURN dans ta procédure ?

  19. #19
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 60
    Points : 31
    Points
    31
    Par défaut
    Pour ce qui est des guillemets pour les mots clés, j'ai testé, mais j'avais toujours le même soucis.
    Maintenant, avec la procédure, je n'ai plus de soucis, mais je n'arrive pas a récupérer dans ma fonction le résultat de ma procédure. (le R en paramètre de ma procédure et GR pour ma fonction)
    Le return, c'est seulement pour sortir de la procédure.

    CALL proc_cherche (ID, USERS, PERMS, GR); fonctionne quand je mets dans ma procédure :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    (ID VARCHAR(36), USERS VARCHAR(250), PERMS VARCHAR(250), INOUT R INTEGER)

Discussions similaires

  1. Réponses: 9
    Dernier message: 25/08/2021, 14h52
  2. Suppression de paramètre pour procédure stockée dans le code
    Par 24 faubourg dans le forum MS SQL Server
    Réponses: 1
    Dernier message: 04/01/2006, 10h51
  3. procédures stockées dans procédure stockée
    Par olivc dans le forum MS SQL Server
    Réponses: 8
    Dernier message: 30/05/2005, 16h58
  4. [PL/SQL] Appel procédure stockée dans trigger
    Par Félia dans le forum Oracle
    Réponses: 3
    Dernier message: 24/01/2005, 17h25
  5. Procédures stockées dans accèss?
    Par joe.lindien dans le forum MS SQL Server
    Réponses: 5
    Dernier message: 21/11/2003, 15h31

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