title: mysql : Passing sql statement as parameter in stored procedure to execute it
body: <p>Please help me with my query:
  I have below mentioned stored procedure in oracle and I need to convert it to MySQL</p>
  
  <pre><code>CREATE OR REPLACE procedure EAMP.EXEC_DDL (SQLSTMT VARCHAR2) AUTHID DEFINER
  is
  BEGIN
  EXECUTE IMMEDIATE SQLSTMT
  END EXEC_DDL;
  /
  </code></pre>
  
  <p>This is what I have created in MySQL (version 5.7):</p>
  
  <pre><code>DROP PROCEDURE IF EXISTS EXEC_DDL;
  CREATE DEFINER=`ampd_own`@`%`
  PROCEDURE `ampd01`.`EXEC_DDL`(in SQLSTMT VARCHAR(4000))
  BEGIN
  set @sql = SQLSTMT;
  PREPARE STMT FROM @sql;
  EXECUTE STMT;
  deallocate prepare STMT;
  END;
  </code></pre>
  
  <p>but it is giving me below mentioned error:</p>
  
  <pre><code>20:08:43  START Executing, Database Connection: EAMP DEV MYSQL Database Type: MYSQL Catalog: ampd01 Schema: null
  20:08:47  INFO  Physical database connection acquired for: EAMP DEV MYSQL  
  20:08:47  WARNING  [DROP - 0 rows, 0.994 secs]  OK. No rows were affected
  SQLWarning: 
  Code: 1305 SQL State: 42000 --- PROCEDURE ampd01.EXEC_DDL does not exist  
  DROP PROCEDURE IF EXISTS EXEC_DDL;
  20:08:48  FAILED  [CREATE - 0 rows, 1.245 secs]  [Code: 1064, SQL State: 
  42000]  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 '' 
  at line 4  
  CREATE DEFINER=`ampd_own`@`%`
  PROCEDURE `ampd01`.`EXEC_DDL`(in SQLSTMT VARCHAR(4000))
  BEGIN
  set @sql = SQLSTMT;
  20:08:49  FAILED  [PREPARE - 0 rows, 1.243 secs]  [Code: 1064, SQL State: 
  42000]  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  
  PREPARE STMT FROM @sql;
  20:08:51  FAILED  [EXECUTE - 0 rows, 1.253 secs]  [Code: 1243, SQL State: 
  HY000]  Unknown prepared statement handler (STMT) given to EXECUTE  
  EXECUTE STMT;
  20:08:52  FAILED  [DEALLOCATE - 0 rows, 1.255 secs]  [Code: 1243, SQL State: 
  HY000]  Unknown prepared statement handler (STMT) given to DEALLOCATE 
  PREPARE  
  deallocate prepare STMT;
  20:08:53  FAILED  [END - 0 rows, 1.253 secs]  [Code: 1064, SQL State: 42000]  
  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 'END' at line 1  
  END;
  20:08:55  END Execution 6 statement(s) executed, 0 row(s) affected, 
  exec/fetch time: 7.243/0.000 secs   [1 successful, 1 Warnings, 5 errors]*/
  </code></pre>