1

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.

0

1 Answer 1

3

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:

  1. variables and conditions
  2. cursors
  3. handlers

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)
Sign up to request clarification or add additional context in comments.

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.