When I didn't use out variable, the stored procedure worked correctly, but when I execute the stored procedure with out variable, this error shows up:
MySQL said: #1327 - Undeclared variable: sp_result
Code:
CREATE DEFINER=`root`@`localhost` PROCEDURE `test3`(OUT `sp_result` INT(11), IN `sp_where_param` VARCHAR(100), IN `sp_where_value` VARCHAR(100), IN `sp_table_name` VARCHAR(100))
NO SQL
BEGIN
DECLARE tbl_id VARCHAR(100);
SET tbl_id = CONCAT(sp_table_name,'_id');
SET @temp1=CONCAT('SELECT count(',tbl_id,') INTO sp_result FROM ',sp_table_name,' WHERE ',sp_where_param,' = \'',sp_where_value,'\'');
PREPARE stmt1 FROM @temp1;
EXECUTE stmt1;
END
Maybe without out variable also doesn't work :(