Created
September 16, 2013 23:39
-
-
Save slav123/6588164 to your computer and use it in GitHub Desktop.
Extra numbers from String SQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select uExtractNumberFromString(mobile) from customer_masterCREATE 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment