Last active
July 22, 2016 08:19
-
-
Save p34eu/1a9edc4d71330817d618765f49da5e3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<sql> | |
CREATE FUNCTION `alphanum`( str CHAR(255) ) RETURNS char(255) CHARSET utf8 | |
BEGIN | |
DECLARE i, len SMALLINT DEFAULT 1; | |
DECLARE ret CHAR(255) DEFAULT ''; | |
DECLARE c CHAR(1); | |
SET len = CHAR_LENGTH( str ); | |
REPEAT | |
BEGIN | |
SET c = MID( str, i, 1 ); | |
#(c REGEXP '[[:alnum:]]') and | |
IF ( (c BETWEEN 'a' AND 'z') OR (c BETWEEN 'A' AND 'Z') OR (c BETWEEN '0' AND '9') OR (c = '-' or c='_') ) THEN | |
SET ret=CONCAT(ret,c); | |
END IF; | |
SET i = i + 1; | |
END; | |
UNTIL i > len END REPEAT; | |
RETURN ret; | |
END | |
</sql> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment