Answer corresponding to this by @Brad Parks Not sure about the MySQL version, but mine was 5.6, hence a little bit tweaking works:
I created a function debug_msg
which is function (not procedure) and returns text(no character limit) and then call the function as SELECT debug_msg
(params) AS my_res_set
, code as below:
CREATE DEFINER=`root`@`localhost` FUNCTION `debug_msg`(`enabled` INT(11), `msg` TEXT) RETURNS text CHARSET latin1
READS SQL DATA
BEGIN
IF enabled=1 THEN
return concat('** DEBUG:', "** ", msg);
END IF;
END
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `proc_func_call`(
IN RegionID VARCHAR(20),
IN RepCurrency INT(11),
IN MGID INT(11),
IN VNC VARCHAR(255)
)
BEGIN
SET @enabled = TRUE;
SET @mainQuery = "SELECT * FROM Users u";
SELECT `debug_msg`(@enabled, @mainQuery) AS `debug_msg1`;
SET @lastQuery = CONCAT(@mainQuery, " WHERE u.age>30);
SELECT `debug_msg`(@enabled, @lastQuery) AS `debug_msg2`;
END $$
DELIMITER