We had a question in #mysql on freenode yesterday, asking if there was a function to strip digits from a string. The answer is of course - not natively.
I’ve been playing around with Functions and Stored Procedures a bit lately though, trying to familiarise myself with the MySQL implementation fully, and wrote this quick function which does the job, although only in 5.0:
DELIMITER //
DROP FUNCTION strip_digits //
CREATE FUNCTION strip_digits (str VARCHAR(50))
RETURNS VARCHAR(50)
BEGIN
DECLARE sub_start INT DEFAULT 0;
DECLARE res VARCHAR(50) DEFAULT '';
WHILE sub_start < LENGTH(str)+1
DO
IF SUBSTRING(str,sub_start,1) REGEXP
'[[:alpha:]]' THEN
…