Skip to content

Instantly share code, notes, and snippets.

@padak
Created July 31, 2014 14:45
Show Gist options
  • Save padak/c0c867452942e4728d48 to your computer and use it in GitHub Desktop.
Save padak/c0c867452942e4728d48 to your computer and use it in GitHub Desktop.
DROP FUNCTION IF EXISTS alphanum;
DELIMITER |
CREATE FUNCTION alphanum( str CHAR(32) ) RETURNS CHAR(16)
BEGIN
DECLARE i, len SMALLINT DEFAULT 1;
DECLARE ret CHAR(32) DEFAULT '';
DECLARE c CHAR(1);
SET len = CHAR_LENGTH( str );
REPEAT
BEGIN
SET c = MID( str, i, 1 );
IF c REGEXP '[[:alnum:]]' THEN
SET ret=CONCAT(ret,c);
END IF;
SET i = i + 1;
END;
UNTIL i > len END REPEAT;
RETURN ret;
END |
DELIMITER ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment