Mysql – How to Solve ERROR 1064 (42000)

MySQLstored-procedures

DROP PROCEDURE IF EXISTS proc_x;
DELIMITER #
CREATE DEFINER=`root`@`localhost`  PROCEDURE proc_x(sequel CHAR)
proc_main:BEGIN
SET @SQL = CONCAT(@sequel);
PREPARE stmt FROM @SQL;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END proc_main #

Above is a syntax for creating stored procedure in my mysql database.
When I execute following statement I get error.

CALL proc_x("INSERT  INTO tbl_rec(id,name,brnachID) values(10,'Krunal',07)");

Error : ERROR 1064 (42000) at line 93: 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 'NULL' at line 1

Can anyone help me to solve it?

Currently I'm using Mysql on UNIX.

Best Answer

(sequel CHAR)
CONCAT(@sequel)

@variables are totally independent of non-@ variables.

Two fixes needed:

  • SET @SQL = CONCAT(@sequel); --> SET @SQL = sequel;
  • (sequel CHAR) --> (sequel VARCHAR(999))