CREATE DEFINER=`root`@`%` FUNCTION `getNum`(str varchar(255) ) RETURNS varchar(255) CHARSET utf8mb4
BEGIN
DECLARE strlength INT DEFAULT 0;
DECLARE temp varchar(50) default '';
SET strlength=CHAR_LENGTH(str);
WHILE strlength > 0 DO
IF (ASCII(mid(str,strlength,1))>47 and ASCII(mid(str,strlength,1))<58 ) THEN
SET temp=concat (temp,mid(str,strlength,1));
END IF;
SET strlength = strlength - 1;
END WHILE;
RETURN REVERSE (temp);
END
例如:
select getNum('你HIA啊123') FROM dual
结果如图
标签:varchar,函数,strlength,mid,查询,str,mysql,255 From: https://www.cnblogs.com/rainbow--/p/17022679.html