Removing numbers from string in mysql
mysql
Solution
I suggest the you manually create a `User Define Function` for this. Here's a great tutorial that you can use
- Extract numbers out of a string
Code Snippet:
DELIMITER $$
DROP FUNCTION IF EXISTS `uExtractNumberFromString`$$
CREATE FUNCTION `uExtractNumberFromString`(in_string varchar(50))
RETURNS INT
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,sChar);
ELSE
SET finNumber=CONCAT(finNumber,'');
END IF;
SET inti=inti+1;
END WHILE;
RETURN CAST(finNumber AS SIGNED INTEGER) ;
ELSE
RETURN 0;
END IF;
END$$
DELIMITER ;
once the function has been created, you can now easily remove the numbers from string, example
SELECT uExtractNumberFromString(Season)
FROM TableName
Problem
I have a string like "FALL01" and i have to remove number from such string so output should look like `Fall` , `spring` and the like. Kindly let me know how can i remove number with sql query . Following is my sample table. Thanks ``` Season ------ FALL01 FALL05 Spring01 Summer06 ```