Write a mysql8 function, the primary key of the parameter table, return the result set of the query statement, do not report 1064 error

CREATE FUNCTION getQueryResults (p_primaryKey VARCHAR(255)) RETURNS result SET @sql = CONCAT('SELECT * FROM table WHERE primary_key = ', p_primaryKey); PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; RETURN result;

Guess you like

Origin blog.csdn.net/weixin_42607969/article/details/129604153