CREATE DEFINER=`chibs_admin`@`%` FUNCTION `Num_char_extract`(Varstring VARCHAR(100)CHARSET utf8, flag INT) RETURNS varchar(50) CHARSET utf8
NO SQL
COMMENT '标识 0 提取数字 1 提取字母 2提取数字+字母 3 提取汉字'
BEGIN
DECLARE len INT DEFAULT 0;
DECLARE Tmp VARCHAR(100) DEFAULT '';
SET len=CHAR_LENGTH(Varstring);
IF flag = 0
THEN
WHILE len > 0 DO
IF MID(Varstring,len,1)REGEXP'[0-9]' THEN
SET Tmp=CONCAT(Tmp,MID(Varstring,len,1));
END IF;
SET len = len - 1;
END WHILE;
ELSEIF flag=1
THEN
WHILE len > 0 DO
IF (MID(Varstring,len,1)REGEXP '[a-zA-Z]')
THEN
SET Tmp=CONCAT(Tmp,MID(Varstring,len,1));
END IF;
SET len = len - 1;
END WHILE;
ELSEIF flag=2
THEN
WHILE len > 0 DO
IF ( (MID(Varstring,len,1)REGEXP'[0-9]'
提取字符串的数字/字母/数字+字母/汉字(存储过程,写sql语句可调用)
于 2021-02-03 17:24:56 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)