I'm attempting to create a MySql Stored Procedure via a Prepare/ Execute statement and I'm getting a error. I don't understand what Syntax I'm breaking.
SET @SourceDBName='dev';
SET @alterstatement=CONCAT('DELIMITER //
CREATE PROCEDURE ',@SourceDBName,'.execute_statement (alterstatement VARCHAR (767))
BEGIN
SELECT @alterstatement;
PREPARE executionstatement FROM @alterstatement;
EXECUTE executionstatement;
END //');
SELECT @alterstatement;
PREPARE executionstatement FROM @alterstatement;
EXECUTE executionstatement;
I get a generic syntax error:
09:43:20 PREPARE executionstatement FROM @alterstatement Error Code: 1064. 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 'DELIMITER // CREATE PROCEDURE dev.execute_statement (alterstatement VARC' at line 1 0.086 sec
Can someone tell me what I'm doing wrong? I've tried troubleshooting, but I haven'y figured it out yet.
DELIMITERis a command of the official command-line utility. You can't use it elsewhere.In your case, you don't need it anyway. The
PREPAREstatement does not accept multiple statements:... so there's no need for separators. However, you'll get this error:
... because
CREATE PROCEDUREis apparently not supported yet: