Two functions that work just like FIND_IN_SET, but support the %
wildcard.
SELECT FIND_IN_WILD_SET('true', 'this,returns,%true%');
SELECT FIND_IN_WILD_SET('true', 'this,returns,%false%');
SELECT FIND_WILD_IN_SET('tr%e', 'this,returns,true');
SELECT FIND_WILD_IN_SET('tr%e', 'this,returns,false');
DROP FUNCTION IF EXISTS FIND_IN_WILD_SET;
DROP FUNCTION IF EXISTS FIND_WILD_IN_SET;
DELIMITER //
CREATE FUNCTION FIND_IN_WILD_SET(theString varchar(65535), theSet varchar(65535))
RETURNS boolean
DETERMINISTIC
BEGIN
DECLARE delimiterCount int;
DECLARE pos int DEFAULT 0;
DECLARE setElement varchar(65535);
DECLARE returnValue boolean DEFAULT FALSE;
SET delimiterCount := CHARACTER_LENGTH(theSet) - CHARACTER_LENGTH(REPLACE(theSet, ',', ''));
WHILE (pos <= delimiterCount) DO
BEGIN
SET setElement := SUBSTRING_INDEX(SUBSTRING_INDEX(theSet, ',', pos+1), ',', -1);
SET returnValue := returnValue OR (theString LIKE setElement); …[Read more]