CREATE DEFINER=`root`@`localhost` FUNCTION `getRoleName`(`rid` text) RETURNS text CHARSET utf8 COLLATE utf8_bin
BEGIN
DECLARE role_name text;
SELECT GROUP_CONCAT(`name`) into role_name from table_name where FIND_IN_SET(id,rid);
RETURN IFNULL(role_name,‘‘);
END
使用
SELECT id,getRoleName(rid) FROM `table_name `