{"id":148,"date":"2011-10-12T11:14:33","date_gmt":"2011-10-12T16:14:33","guid":{"rendered":"http:\/\/thenoyes.com\/littlenoise\/?p=148"},"modified":"2015-07-04T15:44:42","modified_gmt":"2015-07-04T20:44:42","slug":"find_in_wild_set-and-find_wild_in_set","status":"publish","type":"post","link":"https:\/\/thenoyes.com\/littlenoise\/?p=148","title":{"rendered":"FIND_IN_WILD_SET and FIND_WILD_IN_SET"},"content":{"rendered":"<p>Two functions that work just like FIND_IN_SET, but support the % wildcard.<\/p>\n<p>SELECT FIND_WILD_IN_SET(&#8216;%tack&#8217;, &#8216;haystack,bale,heap,needle,pile&#8217;);<br \/>\nSELECT FIND_IN_WILD_SET(&#8216;pin&#8217;, &#8216;haystack,bale,heap,needle,pi%&#8217;);<\/p>\n<pre>DROP FUNCTION IF EXISTS FIND_IN_WILD_SET;\r\nDROP FUNCTION IF EXISTS FIND_WILD_IN_SET;\r\n\r\nDELIMITER \/\/\r\n\r\nCREATE FUNCTION FIND_IN_WILD_SET(theString text, theSet text)\r\nRETURNS boolean\r\nDETERMINISTIC\r\nBEGIN\r\n\r\nDECLARE delimiterCount int;\r\nDECLARE pos int DEFAULT 0;\r\nDECLARE setElement text;\r\nDECLARE returnValue boolean DEFAULT FALSE;\r\n\r\nSET delimiterCount := CHARACTER_LENGTH(theSet) - CHARACTER_LENGTH(REPLACE(theSet, ',', ''));\r\n\r\nWHILE (pos <= delimiterCount) DO\r\n    BEGIN \r\n        SET setElement := SUBSTRING_INDEX(SUBSTRING_INDEX(theSet, ',', pos+1), ',', -1);\r\n        SET returnValue := returnValue OR (theString LIKE setElement);\r\n        SET pos := pos + 1;\r\n\r\n    END;    \r\nEND WHILE;\r\n\r\n\r\nRETURN returnValue;\r\n\r\nEND\/\/\r\n\r\nCREATE FUNCTION FIND_WILD_IN_SET(theString text, theSet text)\r\nRETURNS boolean\r\nDETERMINISTIC\r\nBEGIN\r\n\r\nDECLARE delimiterCount int;\r\nDECLARE pos int DEFAULT 0;\r\nDECLARE setElement text;\r\nDECLARE returnValue boolean DEFAULT FALSE;\r\n\r\nSET delimiterCount := CHARACTER_LENGTH(theSet) - CHARACTER_LENGTH(REPLACE(theSet, ',', ''));\r\n\r\nWHILE (pos <= delimiterCount) DO\r\n    BEGIN \r\n        SET setElement := SUBSTRING_INDEX(SUBSTRING_INDEX(theSet, ',', pos+1), ',', -1);\r\n        SET returnValue := returnValue OR (setElement LIKE theString);\r\n        SET pos := pos + 1;\r\n\r\n    END;    \r\nEND WHILE;\r\n\r\n\r\nRETURN returnValue;\r\n\r\nEND\/\/\r\n\r\nDELIMITER ;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Two functions that work just like FIND_IN_SET, but support the % wildcard. SELECT FIND_WILD_IN_SET(&#8216;%tack&#8217;, &#8216;haystack,bale,heap,needle,pile&#8217;); SELECT FIND_IN_WILD_SET(&#8216;pin&#8217;, &#8216;haystack,bale,heap,needle,pi%&#8217;); DROP FUNCTION IF EXISTS FIND_IN_WILD_SET; DROP FUNCTION IF EXISTS FIND_WILD_IN_SET; DELIMITER \/\/ CREATE FUNCTION FIND_IN_WILD_SET(theString text, theSet text) RETURNS boolean DETERMINISTIC BEGIN DECLARE delimiterCount int; DECLARE pos int DEFAULT 0; DECLARE setElement text; DECLARE returnValue boolean DEFAULT [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4],"tags":[],"class_list":["post-148","post","type-post","status-publish","format-standard","hentry","category-mysql"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2IBF1-2o","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=148"}],"version-history":[{"count":5,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/148\/revisions"}],"predecessor-version":[{"id":391,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/148\/revisions\/391"}],"wp:attachment":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}