时间:2021-07-01 10:21:17 帮助过:17人阅读
该mysql提取出字符串中的数字函数如下:
代码如下:
CREATE FUNCTION GetNum (Varstring varchar(50))
RETURNS varchar(30)
BEGIN
DECLARE v_length INT DEFAULT 0;
DECLARE v_Tmp varchar(50) default '';
set v_length=CHAR_LENGTH(Varstring);
WHILE v_length > 0 DO
IF (ASCII(mid(Varstring,v_length,1))>47 and ASCII(mid(Varstring,v_length,1))<58 ) THEN
set v_Tmp=concat(v_Tmp,mid(Varstring,v_length,1));
END IF;
SET v_length = v_length - 1;
END WHILE;
RETURN REVERSE(v_Tmp);
END;
代码如下:
select GetNum(字段) from table
代码如下:
select GetNum("dfdfd666")
并且该函数可以提取出字符串中非连贯的数字,如:
代码如下:
select GetNum("dfdd111fd666")