0

I am trying to create a mysql stored procedure, but I get this error:

Script line: 2 Failed to CREATE PROCEDURE proc_test_bideep

The stored procedure code is:

DELIMITER $$

DROP PROCEDURE IF EXISTS `commun`.`insert_categorie` $$
CREATE PROCEDURE `commun`.`insert_categorie` (id_mere INT,
                                                                lib_categ VARCHAR(50),
                                                                id_categ_sup INT ,
        categ_authInstantBuy INT)
BEGIN
SET @bg_mere := (SELECT categ_bg FROM categ_basic WHERE categ_id = id_mere);
  
 @bg_mere+2,categ_level_bideep,categ_statut,categ_adult,categ_authSmallBid,categ_authBid,categ_authInstantBuy);
        SELECT '1' AS code_retour;   END IF;
ecetera.........
END $$

DELIMITER ;

2 Answers 2

1

a) You need to DECLARE any variables on the first lines of the procedure, including their datatype:

DECLARE bg_mere INT;

b) To fetch a value from the database into a variable, you use SELECT ... INTO syntax:

SELECT categ_bg INTO bg_mere FROM categ_basic WHERE categ_basic.categ_id = id_mere;

c) You have an END IF without the corresponding IF.

d) The closing END needs a semicolon (not BEGIN though), only then do you need a delimiter to finish the entire statement, and finally you should reset the delimiter back to normal:

BEGIN
  # body of the stored procedure goes here
END;
$$
DELIMITER ;
Sign up to request clarification or add additional context in comments.

Comments

0

Your parameters are missing the keyword IN such as: ...(IN id_mere INT, IN lib_categ ...). Also, you need to configure your OUT variable for @bg_mere in the initial parameter list such as (IN xxx, ..., OUT bg_mere VARCHAR/INT/WHATEVER).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.