Mysql怎么去掉字符串中的数字
作者:互联网
-- 创建一个函数
DELIMITER $$ DROP FUNCTION IF EXISTS `uExtractNumberFromString`$$ CREATE FUNCTION `uExtractNumberFromString`(in_string VARCHAR(50)) RETURNS VARCHAR(50) CHARSET utf8 NO SQL BEGIN DECLARE ctrNumber VARCHAR(50); DECLARE finNumber VARCHAR(50) DEFAULT ' '; DECLARE sChar VARCHAR(2); DECLARE inti INTEGER DEFAULT 1; IF LENGTH(in_string) > 0 THEN WHILE(inti <= LENGTH(in_string)) DO SET sChar= SUBSTRING(in_string,inti,1); SET ctrNumber= FIND_IN_SET(sChar,'0,1,2,3,4,5,6,7,8,9'); IF ctrNumber > 0 THEN SET finNumber=CONCAT(finNumber,''); ELSE SET finNumber=CONCAT(finNumber,sChar); END IF; SET inti=inti+1; END WHILE; RETURN finNumber; ELSE RETURN 0; END IF; END$$ DELIMITER ;
调用函数
SELECT uExtractNumberFromString(字段) FROM `表名`;
标签:VARCHAR,inti,50,finNumber,Mysql,字符串,END,去掉,DECLARE 来源: https://www.cnblogs.com/funian/p/16554818.html