EXECUTE IMMEDIATE MySQL
Category : How-to
Unlike recent versions of Maria DB, MySQL does not currently support the command EXECUTE IMMEDIATE.
Essentially EXECUTE IMMEDIATE is shorthand for perparing a statement, executing a statement and then finally deallocating the prepaired statement.
To get round this limitation in MySQL you can create a stored procedure that wraps up the commands required to execute a statement into a procedure so that you can call it as a one-liner.
CREATE PROCEDURE execute_immediate(IN query MEDIUMTEXT)
MODIFIES SQL DATA
SQL SECURITY DEFINER
SET @q = query;
PREPARE stmt FROM @q;
DEALLOCATE PREPARE stmt;
You can then call the procedure as a one-liner like this:
CALL execute_immediate('QUERY GOES HERE');