I have a table with a column abc that has some special characters like ",.` . I want to remove those and clean up the column using a stored procedure. I have looked up online ( How to remove all non-alpha numeric characters from a string?) and found that the below function that works. But, I need a procedure that I can execute to clean up the column. I am very new to programming and MySQL and using phpMyAdmin to create a routine. Any help on coverting the below and validating would be of great help.
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 ;
Also, How would I run it ? Should I just create a routine and then just use the call statement to clean up the colum ?