MySQL提取字符串中的数字
1 -- 方法1 2 select replace(reverse(FORMAT(reverse('国械注准20173463309'), 0)), ',', ''); 3 4 -- 方法2 5 CREATE FUNCTION get_number (param varchar(50)) 6 7 RETURNS varchar(30) 8 9 BEGIN 10 DECLARE length INT DEFAULT 0; 11 12 DECLARE temp_str varchar(50) default ''; 13 14 set length=CHAR_LENGTH(param); 15 16 WHILE length > 0 DO 17 18 IF (ASCII(mid(param,length,1))>47 and ASCII(mid(param,length,1))<58 )THEN 19 20 set temp_str = concat(temp_str,mid(param,length,1)); 21 22 END IF; 23 24 SET length = length - 1; 25 26 END WHILE; 27 28 RETURN REVERSE(temp_str); 29 30 END; 31 32 33 select get_number('国械注准20173463309');