I've written a stored procedure in order to simplify the process of calling dynamically constructed MySQL statements:


CREATE PROCEDURE statement(IN dynamic_statement TEXT)
      SET @dynamic_statement := dynamic_statement;
      PREPARE prepared_statement FROM @dynamic_statement;
      EXECUTE prepared_statement;
      DEALLOCATE PREPARE prepared_statement;


SET @index := 7;
CALL statement(CONCAT('SELECT ', @index));

My main concern is to code in an easy to read, efficient, and well-structured manner. Feel free to mention the tiniest issue or improvement that comes to your mind, as I am a beginner and I probably need it.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.