I want to add concatenated value to the params variable in mysql procedure. But mysql says it has a syntax error. What is the syntax error I'm doing here?
SET parms =CONCAT('s','sa');
DECLARE CONTINUE HANDLER FOR NOT FOUND SET exit_loop = TRUE;
Mysql complains that the error is in 2nd line. But I think I'm doing something wrong in 1st line.
Your problem is that you put DECLARE
in the wrong place.
DECLARE Syntax
DECLARE is permitted only inside a BEGIN ... END compound statement and must be at its start, before any other statements .
More over the declarations must follow a specific order:
That being said, this will do just fine
DECLARE parms VARCHAR(32);
DECLARE exit_loop INT;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET exit_loop = TRUE;
SET parms = CONCAT('s','sa');
Let's try it:
mysql> DELIMITER // mysql> CREATE PROCEDURE myproc() -> BEGIN -> DECLARE parms VARCHAR(32); -> DECLARE exit_loop INT; -> DECLARE CONTINUE HANDLER FOR NOT FOUND SET exit_loop = TRUE; -> -> SET parms = CONCAT('s','sa'); -> SELECT parms; -> END -> // Query OK, 0 rows affected (0.00 sec) mysql> DELIMITER ; mysql> CALL myproc(); +-------+ | parms | +-------+ | ssa | +-------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.00 sec)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.