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) BEGIN SET @dynamic_statement := dynamic_statement; PREPARE prepared_statement FROM @dynamic_statement; EXECUTE prepared_statement; DEALLOCATE PREPARE prepared_statement; END ;
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.